From 3f8b3ea65df956c23b397913561cc8ebe5403c6e Mon Sep 17 00:00:00 2001 From: sanine Date: Fri, 10 Nov 2023 16:31:53 -0600 Subject: implement vision --- src/simulation/senses.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src') 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( -- cgit v1.2.1