summaryrefslogtreecommitdiff
path: root/src/simulation
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-11-10 16:31:53 -0600
committersanine <sanine.not@pm.me>2023-11-10 16:31:53 -0600
commit3f8b3ea65df956c23b397913561cc8ebe5403c6e (patch)
treece50eeb142101963858d9d8181e5f71c932dfd08 /src/simulation
parent27c786d440b66a0e2e7a168a15396185392a755b (diff)
implement vision
Diffstat (limited to 'src/simulation')
-rw-r--r--src/simulation/senses.js13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/simulation/senses.js b/src/simulation/senses.js
index 87115db..bcfe9df 100644
--- a/src/simulation/senses.js
+++ b/src/simulation/senses.js
@@ -79,26 +79,30 @@ function vision_pos_to_world_pos(world, agent, x, y) {
case 's':
return [agent.x - dx, agent.y - dy];
case 'e':
- return [agent.x + dy, agent.y - dx];
+ return [agent.x - dy, agent.y - dx];
case 'w':
- return [agent.x - dy, agent.y + dx];
+ return [agent.x + dy, agent.y + dx];
}
}
function world_pos_to_vision_idx(world, agent, x, y) {
const [vx, vy] = world_pos_to_vision_pos(world, agent, x, y);
- console.log('vision pos', vx, vy);
return (VIS_WIDTH * vy) + vx;
}
function vision_idx_to_world_pos(world, agent, idx) {
const vx = idx % VIS_WIDTH;
const vy = Math.floor(idx / VIS_WIDTH);
- return vision_pos_to_world_pos(world, agent, vx, vy);
+ const result = vision_pos_to_world_pos(world, agent, vx, vy);
+ console.log([agent.x, agent.y], vx, vy, result);
+ return result;
}
function see_cell(world, x, y) {
const team = 0;
const orientation = 0;
+ if (!world.lattice[y][x]) {
+ throw new Error(`${x}, ${y}`);
+ }
const type = {
active: -0.8,
mutable: -0.4,
@@ -150,7 +154,6 @@ const see = {
const vision = [...Array(VIS_WIDTH*VIS_HEIGHT).keys()]
.map(idx => {
const [x, y] = vision_idx_to_world_pos(world, agent, idx);
- console.log(x, y, idx);
return see_cell(world, x, y);
});
return world.agents.reduce(