summaryrefslogtreecommitdiff
path: root/src/simulation/lattice_rules.test.js
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-11-11 23:05:12 -0600
committersanine <sanine.not@pm.me>2023-11-11 23:05:12 -0600
commit661847f269030c0cbaa681e2d4697873f891cdec (patch)
tree8128128b920d37e50f07647ebfd0078db15f43e0 /src/simulation/lattice_rules.test.js
parentb778ab8b5a547328c044b47c99ec79661283c151 (diff)
fix team information for empty cells
Diffstat (limited to 'src/simulation/lattice_rules.test.js')
-rw-r--r--src/simulation/lattice_rules.test.js58
1 files changed, 32 insertions, 26 deletions
diff --git a/src/simulation/lattice_rules.test.js b/src/simulation/lattice_rules.test.js
index 7648a68..c285711 100644
--- a/src/simulation/lattice_rules.test.js
+++ b/src/simulation/lattice_rules.test.js
@@ -11,11 +11,17 @@ function apply(f, n, x0) {
}
+// remove cell team information
+function clean_team(lattice) {
+ return lattice.map(row => row.map(cell => ({...cell, flags: {...cell.flags, team: undefined } })));
+}
+
+
test("blinker", () => {
- const L = { type: 'active', flags: {} };
- const _ = { type: 'empty', flags: {} };
- const l = { type: 'active', flags: { emit: [0, 0, 0, 0, 0, 0, 0, 1] } };
- const d = { type: 'empty', flags: { emit: [0, 0, 0, 0, 0, 0, 0, -1] } };
+ const L = { type: 'active', flags: { team: undefined, } };
+ const _ = { type: 'empty', flags: { team: undefined, } };
+ const l = { type: 'active', flags: { team: undefined, emit: [0, 0, 0, 0, 0, 0, 0, 1] } };
+ const d = { type: 'empty', flags: { team: undefined, emit: [0, 0, 0, 0, 0, 0, 0, -1] } };
const lattice = [
[ _, _, _, _, _ ],
[ _, _, _, _, _ ],
@@ -25,14 +31,14 @@ test("blinker", () => {
];
const world = { lattice, lattice_rules, agents: [], senses: [], actions: [], validity: [] };
- expect(world_update(world).lattice).toEqual([
+ expect(clean_team(world_update(world).lattice)).toEqual([
[ _, _, _, _, _ ],
[ _, _, l, _, _ ],
[ _, d, L, d, _ ],
[ _, _, l, _, _ ],
[ _, _, _, _, _ ],
]);
- expect(world_update(world_update(world)).lattice).toEqual([
+ expect(clean_team(world_update(world_update(world)).lattice)).toEqual([
[ _, _, _, _, _ ],
[ _, _, d, _, _ ],
[ _, l, L, l, _ ],
@@ -43,10 +49,10 @@ test("blinker", () => {
test("glider", () => {
- const L = { type: 'active', flags: {} };
- const _ = { type: 'empty', flags: {} };
- const l = { type: 'active', flags: { emit: [0, 0, 0, 0, 0, 0, 0, 1] } };
- const d = { type: 'empty', flags: { emit: [0, 0, 0, 0, 0, 0, 0, -1] } };
+ const L = { type: 'active', flags: { team: undefined, } };
+ const _ = { type: 'empty', flags: { team: undefined, } };
+ const l = { type: 'active', flags: { team: undefined, emit: [0, 0, 0, 0, 0, 0, 0, 1] } };
+ const d = { type: 'empty', flags: { team: undefined, emit: [0, 0, 0, 0, 0, 0, 0, -1] } };
const lattice = [
[ _, _, _, _, _, _ ],
[ _, _, _, L, _, _ ],
@@ -57,8 +63,8 @@ test("glider", () => {
];
const world = { lattice, lattice_rules, agents: [], senses: [], actions: [], validity: [] };
- //expect(world_update(world).lattice).toEqual([
- expect(apply(world_update, 1, world).lattice).toEqual([
+ //expect(clean_team(world_update(world).lattice)).toEqual([
+ expect(clean_team(apply(world_update, 1, world).lattice)).toEqual([
[ _, _, _, _, _, _ ],
[ _, _, l, d, _, _ ],
[ _, d, _, L, l, _ ],
@@ -66,7 +72,7 @@ test("glider", () => {
[ _, _, _, _, _, _ ],
[ _, _, _, _, _, _ ],
]);
- expect(apply(world_update, 2, world).lattice).toEqual([
+ expect(clean_team(apply(world_update, 2, world).lattice)).toEqual([
[ _, _, _, _, _, _ ],
[ _, _, d, l, _, _ ],
[ _, _, _, d, L, _ ],
@@ -74,7 +80,7 @@ test("glider", () => {
[ _, _, _, _, _, _ ],
[ _, _, _, _, _, _ ],
]);
- expect(apply(world_update, 3, world).lattice).toEqual([
+ expect(clean_team(apply(world_update, 3, world).lattice)).toEqual([
[ _, _, _, _, _, _ ],
[ _, _, _, d, _, _ ],
[ _, _, l, _, L, _ ],
@@ -82,7 +88,7 @@ test("glider", () => {
[ _, _, _, l, _, _ ],
[ _, _, _, _, _, _ ],
]);
- expect(apply(world_update, 4, world).lattice).toEqual([
+ expect(clean_team(apply(world_update, 4, world).lattice)).toEqual([
[ _, _, _, _, _, _ ],
[ _, _, _, _, _, _ ],
[ _, _, d, _, L, _ ],
@@ -94,8 +100,8 @@ test("glider", () => {
test("beehive", () => {
- const L = { type: 'active', flags: {} };
- const _ = { type: 'empty', flags: {} };
+ const L = { type: 'active', flags: { team: undefined, } };
+ const _ = { type: 'empty', flags: { team: undefined, } };
const lattice = [
[ _, _, _, _, _, _ ],
[ _, _, L, L, _, _ ],
@@ -105,17 +111,17 @@ test("beehive", () => {
];
const world = { lattice, lattice_rules, agents: [], senses: [], actions: [], validity: [] };
- //expect(world_update(world).lattice).toEqual([
- expect(apply(world_update, 1, world).lattice).toEqual(lattice);
+ //expect(clean_team(world_update(world).lattice)).toEqual([
+ expect(clean_team(apply(world_update, 1, world).lattice)).toEqual(lattice);
});
test("mutables are activated by neighboring actives", () => {
- const L = { type: 'active', flags: {} };
- const _ = { type: 'empty', flags: {} };
- const l = { type: 'active', flags: { emit: [0, 0, 0, 0, 0, 0, 0, 1] } };
- const d = { type: 'empty', flags: { emit: [0, 0, 0, 0, 0, 0, 0, -1] } };
- const M = { type: 'mutable', flags: {} };
+ const L = { type: 'active', flags: { team: undefined, } };
+ const _ = { type: 'empty', flags: { team: undefined, } };
+ const l = { type: 'active', flags: { team: undefined, emit: [0, 0, 0, 0, 0, 0, 0, 1] } };
+ const d = { type: 'empty', flags: { team: undefined, emit: [0, 0, 0, 0, 0, 0, 0, -1] } };
+ const M = { type: 'mutable', flags: { team: undefined, } };
const lattice = [
[ _, _, _, _, ],
@@ -126,13 +132,13 @@ test("mutables are activated by neighboring actives", () => {
const world = { lattice, lattice_rules, agents: [], senses: [], actions: [], validity: [] };
- expect(apply(world_update, 1, world).lattice).toEqual([
+ expect(clean_team(apply(world_update, 1, world).lattice)).toEqual([
[ _, _, _, _, ],
[ _, L, l, _, ],
[ _, l, l, _, ],
[ _, _, _, _, ],
]);
- expect(apply(world_update, 2, world).lattice).toEqual([
+ expect(clean_team(apply(world_update, 2, world).lattice)).toEqual([
[ _, _, _, _, ],
[ _, L, L, _, ],
[ _, L, L, _, ],