summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Paul <n@nc0.fr>2024-03-07 13:30:12 +0100
committerNicolas Paul <n@nc0.fr>2024-03-08 23:12:55 +0100
commitaed09fee6dfe278cfceafb56a4d4f14c84a737a8 (patch)
tree575b6dcbdb1fc66db88770e58c53170079fab903
parent39748129f1f6c142857fa12a815c08aa31931953 (diff)
game: Add Barrier cell type
Barrier cells are cells that never change and are not affected by rules (hardcoded behavior in the Rule class). Barriers can be used by boards to shape their board, e.g. // `#` for barriers, `.` for empty, `a` for team A, and `b` for // team B. const board = [ "####################", "####...######...####", "###aa....##..b...###", "##a....a...bb.....##", "###....aabbbb....###", "#####...a.bb...#####", "########a...########", "#########..#########", "####################" ]; // 20x9 heart shaped As illustrated, boards stay list of strings, but thanks to the barrier, they can adopt specific shapes. A regular array shaped board unifies the API between downstream users and our internal states. Signed-off-by: Nicolas Paul <n@nc0.fr>
-rw-r--r--life2/game/cell.js2
-rw-r--r--life2/game/rule.js1
2 files changed, 3 insertions, 0 deletions
diff --git a/life2/game/cell.js b/life2/game/cell.js
index e232366..cd5274f 100644
--- a/life2/game/cell.js
+++ b/life2/game/cell.js
@@ -36,4 +36,6 @@ export const Cell = {
TEAM_A: 1,
/** The cell is filled with the color of the second team. */
TEAM_B: 2,
+ /** The cell is a barrier, it is never affected by rules. */
+ BARRIER: 3,
};
diff --git a/life2/game/rule.js b/life2/game/rule.js
index 5a2b1f2..ee723db 100644
--- a/life2/game/rule.js
+++ b/life2/game/rule.js
@@ -88,6 +88,7 @@ export class Rule {
* apply to the cell.
*/
execute(cell, neighbors) {
+ if (cell === Cell.BARRIER) return null;
return this.expression_(cell, neighbors);
}
}