/
flags.ml
27 lines (23 loc) · 870 Bytes
/
flags.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
(* Flags are just strings stored in the state's `flags` property
* All they do is keep track of things the player has done like various booleans
*)
open Types
(* Add a flag to the state *)
let add_flag (state: game_state) (flag: string) : game_state = {
state with flags = flag::state.flags
}
(* Determine if the state has a specific flag *)
let has_flag ({flags; _}: game_state) (flag: string) : bool =
List.exists ((=)flag) flags
(* Remove a flag only upon the first encounter *)
let remove_flag (state: game_state) (flag: string) : game_state = {
state with flags =
let rec find = function
| x::xs -> if x = flag then xs else x::find xs
| [] -> []
in find state.flags
}
(* Remove every instance of a flag *)
let remove_flags (state: game_state) (flag: string) : game_state = {
state with flags = List.filter ((!=)flag) state.flags
}