summaryrefslogtreecommitdiff
path: root/src/world/sense.test.js
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-11-08 00:47:06 -0600
committersanine <sanine.not@pm.me>2023-11-08 00:47:06 -0600
commitf78493e192daf4639b91352909e4029b9970fcdb (patch)
tree5b43952cc5da05ffcc942d079f0c3b60674060be /src/world/sense.test.js
parent3ae8f476f3865982ca69d0e39b05b5aa8ec43694 (diff)
implement basic sensing & refactor world/cells -> lattice
Diffstat (limited to 'src/world/sense.test.js')
-rw-r--r--src/world/sense.test.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/world/sense.test.js b/src/world/sense.test.js
new file mode 100644
index 0000000..1ef7bce
--- /dev/null
+++ b/src/world/sense.test.js
@@ -0,0 +1,33 @@
+import { sense_read } from './sense.js';
+
+
+test("basic sense works", () => {
+ const flag_sense = {
+ size: 1,
+ read: (lattice, agent) => {
+ const {x, y} = agent;
+ return [ lattice[y-1][x].type === 'flag' ? 1.0 : 0.0 ]
+ },
+ };
+
+ const lattice = [[ { type: 'flag' } ]];
+ const agent = { x: 0, y: 1 };
+
+ expect(sense_read(lattice, agent, flag_sense)).toEqual([1.0]);
+});
+
+
+test("senses throw if the size is incorrect", () => {
+ const flag_sense = {
+ size: 2,
+ read: (lattice, agent) => {
+ const {x, y} = agent;
+ return [ lattice[y-1][x].type === 'flag' ? 1.0 : 0.0 ]
+ },
+ }
+
+ const lattice = [[ { type: 'flag' } ]];
+ const agent = { x: 0, y: 1 };
+
+ expect(() => sense_read(lattice, agent, flag_sense)).toThrow();
+});