summaryrefslogtreecommitdiff
path: root/src/simulation/senses.test.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/simulation/senses.test.js')
-rw-r--r--src/simulation/senses.test.js90
1 files changed, 86 insertions, 4 deletions
diff --git a/src/simulation/senses.test.js b/src/simulation/senses.test.js
index 1caed52..b54ada2 100644
--- a/src/simulation/senses.test.js
+++ b/src/simulation/senses.test.js
@@ -2,7 +2,7 @@
import { senses } from './senses.js';
-const [ frozen, ...rest ] = senses;
+const [ frozen, hear, ...rest ] = senses;
test("frozen sense", () => {
@@ -10,9 +10,91 @@ test("frozen sense", () => {
id: 0, x: 0, y: 0,
flags: { frozen: true, },
};
- const lattice = null;
- expect(frozen.read(lattice, agent)).toEqual([1]);
+ expect(frozen.read(null, agent)).toEqual([1]);
agent.flags.frozen = false;
- expect(frozen.read(lattice, agent)).toEqual([0]);
+ expect(frozen.read(null, agent)).toEqual([0]);
+});
+
+
+test("hear nothing", () => {
+ const agent = { id: 4, x: 1, y: 1, flags: {} };
+ const o = { type: 'empty', flags: {} };
+ const world = {
+ lattice: [
+ [ o, o, o ],
+ [ o, o, o ],
+ [ o, o, o ],
+ ],
+ agents: [agent],
+ };
+
+ expect(hear.read(world, agent)).toEqual([
+ Math.tanh(0), Math.tanh(0), Math.tanh(0), Math.tanh(0),
+ Math.tanh(0), Math.tanh(0), Math.tanh(0), Math.tanh(0),
+ ]);
+});
+
+
+test("hear self", () => {
+ const agent = { id: 4, x: 1, y: 1, flags: { emit: [1, 0, 0.5, 0, 0, 0, 0, 1] } };
+ const o = { type: 'empty', flags: {} };
+ const world = {
+ lattice: [
+ [ o, o, o ],
+ [ o, o, o ],
+ [ o, o, o ],
+ ],
+ agents: [agent],
+ };
+
+ expect(hear.read(world, agent)).toEqual([
+ Math.tanh(1), Math.tanh(0), Math.tanh(0.5), Math.tanh(0),
+ Math.tanh(0), Math.tanh(0), Math.tanh(0), Math.tanh(1),
+ ]);
+});
+
+
+test("hear cells", () => {
+ const agent = { id: 4, x: 2, y: 2, flags: {} };
+ const o = { type: 'empty', flags: {} };
+ const s = { type: 'empty', flags: { emit: [1, 0.5, 0.25, 0.125, 0, 0, 0, 0] } };
+ const world = {
+ lattice: [
+ [ o, o, s, o, o ],
+ [ o, o, o, o, o ],
+ [ o, s, o, o, o ],
+ [ o, o, o, o, o ],
+ [ o, o, o, o, o ],
+ ],
+ agents: [agent],
+ };
+
+ expect(hear.read(world, agent)).toEqual([
+ Math.tanh(1.25), Math.tanh(0.625), Math.tanh(0.3125), Math.tanh(0.15625),
+ Math.tanh(0), Math.tanh(0), Math.tanh(0), Math.tanh(0),
+ ]);
+});
+
+
+test("hear cells & agents", () => {
+ const agent = { id: 4, x: 2, y: 2, flags: {} };
+ const agent2 = { id: 0, x: 2, y: 4, flags: { emit: [0, 0, 0, 0, 1, 1, 1, 1] } };
+ const o = { type: 'empty', flags: {} };
+ const s = { type: 'empty', flags: { emit: [1, 0.5, 0.25, 0.125, 0, 0, 0, 0] } };
+ const world = {
+ lattice: [
+ [ o, o, s, o, o ],
+ [ o, o, o, o, o ],
+ [ o, s, o, o, o ],
+ [ o, o, o, o, o ],
+ [ o, o, o, o, o ],
+ ],
+ agents: [agent, agent2],
+ };
+
+ expect(hear.read(world, agent)).toEqual([
+ Math.tanh(1.25), Math.tanh(0.625), Math.tanh(0.3125), Math.tanh(0.15625),
+ Math.tanh(0.25), Math.tanh(0.25), Math.tanh(0.25), Math.tanh(0.25),
+ ]);
});