summaryrefslogtreecommitdiff
path: root/src/simulation/lattice_rules.js
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-11-11 15:10:55 -0600
committersanine <sanine.not@pm.me>2023-11-11 15:10:55 -0600
commitf995438c0e72e1d08203609d74854d07dbecd661 (patch)
treeb3e6c4f73526c61d9d6e5c4519b86fe0deaeb36f /src/simulation/lattice_rules.js
parentf7b0ed22b2fd0ddafc4a84dde1ad8e3208144844 (diff)
mutables can be activated by living neighbors
Diffstat (limited to 'src/simulation/lattice_rules.js')
-rw-r--r--src/simulation/lattice_rules.js14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/simulation/lattice_rules.js b/src/simulation/lattice_rules.js
index db027a3..80f3221 100644
--- a/src/simulation/lattice_rules.js
+++ b/src/simulation/lattice_rules.js
@@ -53,7 +53,19 @@ export const lattice_rules = {
}
},
- mutable: () => {},
+ mutable: (lattice, x, y) => {
+ const num_active_neighbors = neighbors(lattice, x, y)
+ .map(([x, y, cell]) => cell.type)
+ .filter(type => type === 'active')
+ .length;
+ if (num_active_neighbors > 0) {
+ // become living cell
+ return { world_updates: [{
+ x, y, from: 'empty', to: 'active',
+ flags: { emit: [0, 0, 0, 0, 0, 0, 0, 1] },
+ }]};
+ }
+ },
immutable: () => {},
flag: () => {},