summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Paul <n@nc0.fr>2024-03-07 18:04:42 +0100
committerNicolas Paul <n@nc0.fr>2024-03-08 23:12:55 +0100
commita58e2e1b2792388f4f58f354918207c18ef43d95 (patch)
tree8e3ec0efa735c4837d9c1000853a7da3b680fdef
parent84061c97957b26c0bbb32d4fa2641569e0ee8f43 (diff)
Remove the state computation logic from Board
This patch removes the logic of computing the next state of a board to the Board class. Instead, this will be the responsability of the World class. The rational behind this change is that it will simplifies the reasoning about the Board as only being a geometrical data structure, leaving the class to a single responsability. On the other hand, the World class, which is already the manager of the game loop, will see its logic simplified by being able to directly compute the next state, instead of relying on its dependency on a Board. Signed-off-by: Nicolas Paul <n@nc0.fr>
-rw-r--r--life2/game/board.js13
-rw-r--r--life2/game/cell.js2
-rw-r--r--life2/game/rule.js2
3 files changed, 5 insertions, 12 deletions
diff --git a/life2/game/board.js b/life2/game/board.js
index d9d508f..19c3b28 100644
--- a/life2/game/board.js
+++ b/life2/game/board.js
@@ -17,8 +17,6 @@
/**
* @fileoverview A board is a grid of cells in a certain shape and size.
- * The board is responsible for computing the next state of the game based on
- * its current state and a set of rules.
* To make the game more interesting, the board can be configured to have
* different 2D shapes (from the classic rectangle to more complex shapes like
* hexagons).
@@ -66,8 +64,9 @@ export let Grid;
/**
* A board is a grid of cells shaped after any valid 2D shape.
- * The board is responsible for computing the next state of the game based on
- * its current state and a set of rules that is passed to it.
+ * The board is only responsible for storing the cells and their state in a
+ * geometric shape. It does not apply any rules or logic to the cells, that is
+ * the responsibility of the World.
* @interface
*/
export class Board {
@@ -96,12 +95,6 @@ export class Board {
*/
getNeighbors(x, y) {}
/**
- * Calculate the next state of the board based on a set of rules.
- * @param {!Array<!Rule>} rules The rules to apply to the board.
- * @abstract
- */
- calculateNextState(rules) {}
- /**
* Check if a position is out of bounds.
* @param {number} x The x position of the cell.
* @param {number} y The y position of the cell.
diff --git a/life2/game/cell.js b/life2/game/cell.js
index cd5274f..c5f13ec 100644
--- a/life2/game/cell.js
+++ b/life2/game/cell.js
@@ -18,7 +18,7 @@
/**
* @fileoverview Implementation of a cell in the Life2 game.
* Cells are the smallest unit of the game, they carry information about their
- * aliveness and their team, but everything else is computed by the board
+ * aliveness and their team, but everything else is computed by the game World
* (interactions, changes, ...).
*
* @package life2
diff --git a/life2/game/rule.js b/life2/game/rule.js
index ee723db..19e32f4 100644
--- a/life2/game/rule.js
+++ b/life2/game/rule.js
@@ -20,7 +20,7 @@
* the next state of a cell based on its current state within a board.
* Rules are functions that either return a new cell state, or nothing if they
* don't apply to the cell.
- * The final choice for a cell state is made by the board, using all the results
+ * The final choice for a cell state is made by the World, using all the results
* from the multiple rules being applied to the cell.
*
* @package life2