-const state_next = (state : State, neighbor_states : Array<State>) : State => {
- const neighbors_alive = neighbor_states.filter(state_is_alive).length;
- if (state === "Alive" && neighbors_alive < 2) {
- return "Dead"
- } else if (state === "Alive" && neighbors_alive < 4) {
- return "Alive"
- } else if (state === "Alive" && neighbors_alive > 3) {
- return "Dead"
- } else if (state === "Dead" && neighbors_alive === 3) {
- return "Alive"
- } else {
- return state
- }
-}
-
-const board_next = (b0 : Board) : Board => {
- const b1 = b0.map(
- (location) => {
- const neighbor_locations = b0.moore_neighbors(location);
- const neighbor_states = neighbor_locations.map((l) => b0.get(l));
- const state_0 = b0.get(location);
- const state_1 = state_next(state_0, neighbor_states);
- return state_1
- }
- );
- return b1
-};
+ export class Board {
+ private grid: Grid<State.T>;
+
+ constructor(
+ {rows, columns} :
+ { rows : number
+ , columns : number
+ }
+ )
+ {
+ const init = (_) => State.of_integer(Math.round(Math.random()));
+ this.grid = new Grid({rows: rows, columns: columns, init: init});
+ };