summaryrefslogtreecommitdiff
path: root/src/simulation/lattice_rules.js
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-11-16 14:50:00 -0600
committersanine <sanine.not@pm.me>2023-11-16 14:50:00 -0600
commitf9fc4d26ec5fca9ee175c8a6fbcdd0fa36f10947 (patch)
treef190e6e465bb563c608a916f41fc8bf686ea2897 /src/simulation/lattice_rules.js
parent7825b92ce3be95a0ce1dfea9388adbaadce83b1f (diff)
clear out js files
Diffstat (limited to 'src/simulation/lattice_rules.js')
-rw-r--r--src/simulation/lattice_rules.js77
1 files changed, 0 insertions, 77 deletions
diff --git a/src/simulation/lattice_rules.js b/src/simulation/lattice_rules.js
deleted file mode 100644
index cc2fc5b..0000000
--- a/src/simulation/lattice_rules.js
+++ /dev/null
@@ -1,77 +0,0 @@
-import { pairs } from '../util.js';
-import { get_team } from './game.js';
-
-function mod(k, n) {
- return ((k % n) + n) % n;
-}
-
-function pos_wrap(lattice, x, y) {
- const height = lattice.length;
- const width = lattice[0].length;
- return [mod(x, width), mod(y, height)];
-}
-
-
-function neighbors(lattice, x, y) {
- const offsets = [-1, 0, 1];
- const positions = pairs(offsets, offsets)
- .filter(([dx, dy]) => dx !== 0 || dy !== 0)
- .map(([dx, dy]) => pos_wrap(lattice, x+dx, y+dy));
- const neighbors = positions
- .map(([x, y]) => [x, y, lattice[y][x]]);
- return neighbors;
-}
-
-
-export const lattice_rules = {
-
- empty: (lattice, x, y) => {
- const num_active_neighbors = neighbors(lattice, x, y)
- .map(([x, y, cell]) => cell.type)
- .filter(type => type === 'mutable' || type === 'active')
- .length;
- if (num_active_neighbors === 3) {
- return { world_updates: [{
- x, y, from: 'empty', to: 'active',
- flags: { emit: [0, 0, 0, 0, 0, 0, 0, 1] },
- }]};
- } else {
- return { world_updates: [{
- x, y, flags: { team: get_team(lattice.length, x, y) },
- }]};
- }
- },
-
- active: (lattice, x, y) => {
- const num_active_neighbors = neighbors(lattice, x, y)
- .map(([x, y, cell]) => cell.type)
- .filter(type => type === 'mutable' || type === 'active')
- .length;
- const die = { world_updates: [{
- x, y, from: 'active', to: 'empty',
- flags: { emit: [0, 0, 0, 0, 0, 0, 0, -1] },
- }]};
- if (num_active_neighbors < 2) {
- return die;
- } else if (num_active_neighbors > 3) {
- return die;
- }
- },
-
- 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: () => {},
-
-};