From f78493e192daf4639b91352909e4029b9970fcdb Mon Sep 17 00:00:00 2001 From: sanine Date: Wed, 8 Nov 2023 00:47:06 -0600 Subject: implement basic sensing & refactor world/cells -> lattice --- src/world/sense.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/world/sense.js (limited to 'src/world/sense.js') diff --git a/src/world/sense.js b/src/world/sense.js new file mode 100644 index 0000000..47329b7 --- /dev/null +++ b/src/world/sense.js @@ -0,0 +1,17 @@ +'use strict'; + +/* sense structure: + * { + * size: number + * read: function(lattice, agent) -> number[size] + * } + */ + + +export function sense_read(lattice, agent, sense) { + const result = sense.read(lattice, agent); + if (result.length !== sense.size) { + throw new Error(`Expected result of size ${sense.size}, but got ${result.length} instead.`); + } + return sense.read(lattice, agent); +} -- cgit v1.2.1