+ 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 state ~burning_neighbors =
+ match state, 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
+
+ let burning_neighbors inputs =
+ inputs
+ |> List.filter_map ~f:(function "B" -> Some 1 | _ -> None)
+ |> List.fold_left ~init:0 ~f:(+)
+
+ let transition ~state ~inputs =
+ state
+ |> state_of_string
+ |> next ~burning_neighbors:(burning_neighbors inputs)
+ |> cell_of_state