summaryrefslogtreecommitdiff
path: root/src/simulation
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-11-09 17:06:48 -0600
committersanine <sanine.not@pm.me>2023-11-09 17:06:48 -0600
commit1b92f501c40eded57d66946ff717e49a5362f7c3 (patch)
tree4c25b5dc51e4a5d6ca4f0630d784cd7dde56681a /src/simulation
parentd6c0a0830d6c61ea7c88ab6dff8189904ade4578 (diff)
add senses.js
Diffstat (limited to 'src/simulation')
-rw-r--r--src/simulation/senses.js18
-rw-r--r--src/simulation/senses.test.js18
2 files changed, 36 insertions, 0 deletions
diff --git a/src/simulation/senses.js b/src/simulation/senses.js
new file mode 100644
index 0000000..4fc96d6
--- /dev/null
+++ b/src/simulation/senses.js
@@ -0,0 +1,18 @@
+'use strict';
+
+
+const frozen = {
+ size: 1,
+ read: (lattice, agent) => {
+ if (agent.flags.frozen === true) {
+ return [ 1 ];
+ } else {
+ return [ 0 ];
+ }
+ },
+};
+
+
+export const senses = [
+ frozen,
+];
diff --git a/src/simulation/senses.test.js b/src/simulation/senses.test.js
new file mode 100644
index 0000000..1caed52
--- /dev/null
+++ b/src/simulation/senses.test.js
@@ -0,0 +1,18 @@
+'use strict';
+
+import { senses } from './senses.js';
+
+const [ frozen, ...rest ] = senses;
+
+
+test("frozen sense", () => {
+ const agent = {
+ id: 0, x: 0, y: 0,
+ flags: { frozen: true, },
+ };
+ const lattice = null;
+
+ expect(frozen.read(lattice, agent)).toEqual([1]);
+ agent.flags.frozen = false;
+ expect(frozen.read(lattice, agent)).toEqual([0]);
+});