+ val of_cell_state : Cell.State.t -> t
+
+ val next : t -> burning_neighbors:int -> t
+ end =
+ struct
+ type t = E | T | B
+
+ let is_burning = function
+ | E -> false
+ | T -> false
+ | B -> true
+
+ let random () =
+ match Random.int 3 with
+ | 0 -> E
+ | 1 -> T
+ | 2 -> B
+ | _ -> assert false
+
+ let to_pheno = function
+ | E -> PhenoType.make ' ' None
+ | T -> PhenoType.make 'T' (Some `green)
+ | B -> PhenoType.make '#' (Some `red)
+
+ let of_cell_state = function
+ | Cell.State.Dead -> E
+ | Cell.State.Alive Cell.State.Friendly -> T
+ | Cell.State.Alive Cell.State.Neutral -> E
+ | Cell.State.Alive Cell.State.Hostile -> B
+
+ let to_cell_state = function
+ | E -> Cell.State.Dead
+ | T -> Cell.State.Alive Cell.State.Friendly
+ | B -> Cell.State.Alive Cell.State.Hostile
+
+ let to_cell t =
+ { Cell.state = t |> to_cell_state
+ ; Cell.pheno = t |> to_pheno
+ }
+
+ let f = 0.000001 (* Probability of spontaneous ignition *)
+ let p = 0.1 (* Probability of spontaneous growth *)
+
+ let is_probable p =
+ (Random.float 1.0) <= p
+
+ let next t ~burning_neighbors =
+ match t, burning_neighbors with
+ | E, _ when is_probable p -> T
+ | E, _ -> E
+ | T, 0 when is_probable f -> B
+ | T, _ when burning_neighbors > 0 -> B
+ | T, _ -> T
+ | B, _ -> E
+ end