'use strict'; import { senses } from './senses.js'; const [ frozen, hear, ...rest ] = senses; test("frozen sense", () => { const agent = { id: 0, x: 0, y: 0, flags: { frozen: true, }, }; expect(frozen.read(null, agent)).toEqual([1]); agent.flags.frozen = false; 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), ]); });