package elm_playground_gamekits
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
Genre kits for Playground games: platformers, racing, shoot 'em ups, fighting and more
Install
dune-project
Dependency
Authors
Maintainers
Sources
0.3.6.tar.gz
md5=7c636383d146d30ac6f2fa234a6253c8
sha512=c79f3823c5f8f57e5038eb640d487c61168b84aa07c61999d6622ef9fd0c890e2b03b4c6a7cdbbe9352a49e25dda00ac7bb14693cee8e3d7beeed251351a2af0
doc/src/elm_playground_gamekits.kit_adventure/Adventure.ml.html
Source file Adventure.ml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63(* Claude Code * * Copyright (C) 2026 Yoann Padioleau * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public License * (LGPL) as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. *) (* See Adventure.mli *) type place = Room of string | Carried | Inside of string | Nowhere type world = { here : string; places : (string * place) list; flags : string list; score : int; turns : int } let start (room : string) (places : (string * place) list) : world = { here = room; places; flags = []; score = 0; turns = 0 } let where (w : world) (obj : string) : place = match List.assoc_opt obj w.places with Some p -> p | None -> Nowhere let put (obj : string) (p : place) (w : world) : world = { w with places = List.map (fun (o, q) -> if o = obj then (o, p) else (o, q)) w.places } let go (room : string) (w : world) : world = { w with here = room } let has (w : world) (flag : string) : bool = List.mem flag w.flags let set (flag : string) (w : world) : world = if has w flag then w else { w with flags = flag :: w.flags } let unset (flag : string) (w : world) : world = { w with flags = List.filter (( <> ) flag) w.flags } let rec visible (w : world) (obj : string) : bool = match where w obj with | Room r -> r = w.here | Carried -> true | Inside c -> has w (c ^ " open") && visible w c | Nowhere -> false let in_room (w : world) : string list = List.filter_map (fun (o, p) -> if p = Room w.here then Some o else None) w.places let carried (w : world) : string list = List.filter_map (fun (o, p) -> if p = Carried then Some o else None) w.places type sentence = { verb : string; obj : string option; with_ : string option } type rule = { verb : string; obj : string option; with_ : string option; test : sentence -> world -> bool; act : sentence -> world -> world * string; } let any = Some "*" let always (_ : sentence) (_ : world) : bool = true let matches (pattern : string option) (o : string option) : bool = match (pattern, o) with Some "*", Some _ -> true | _ -> pattern = o let run (rules : rule list) (s : sentence) (w : world) : world * string = let w = { w with turns = w.turns + 1 } in let unseen = List.filter (fun o -> not (visible w o)) (Option.to_list s.obj @ Option.to_list s.with_) in match unseen with | o :: _ -> (w, "You see no " ^ o ^ " here.") | [] -> ( match List.find_opt (fun (r : rule) -> r.verb = s.verb && matches r.obj s.obj && matches r.with_ s.with_ && r.test s w) rules with | Some r -> r.act s w | None -> (w, "You can't do that."))
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>