- | 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
+ | State.E, _ when is_probable p -> State.T
+ | State.E, _ -> State.E
+ | State.T, 0 when is_probable f -> State.B
+ | State.T, _ when burning_neighbors > 0 -> State.B
+ | State.T, _ -> State.T
+ | State.B, _ -> State.E
+
+ let burning_neighbors neighbors =
+ neighbors |> List.map ~f:State.of_cell_state
+ |> List.filter ~f:State.is_burning
+ |> List.map ~f:State.to_int
+ |> List.fold_left ~init:0 ~f:(+)
+
+ let transition ~self ~neighbors =
+ self |> State.of_cell_state
+ |> next ~burning_neighbors:(burning_neighbors neighbors)
+ |> State.to_cell