diff options
author | sanine <sanine.not@pm.me> | 2023-11-12 11:48:41 -0600 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2023-11-12 11:48:41 -0600 |
commit | 22fe18beac4459427c2b40499afafc7c5c868691 (patch) | |
tree | 63acbe33339af6f52501094d6466cb35643d4bfc /src | |
parent | a443171f51cf2d3b3a6c8f4e4967a3d19fd111d3 (diff) |
fix bug with too many vision outputs
Diffstat (limited to 'src')
-rw-r--r-- | src/simulation/game.js | 2 | ||||
-rw-r--r-- | src/simulation/senses.js | 6 |
2 files changed, 5 insertions, 3 deletions
diff --git a/src/simulation/game.js b/src/simulation/game.js index 17b1442..05ac4a1 100644 --- a/src/simulation/game.js +++ b/src/simulation/game.js @@ -72,7 +72,7 @@ export function create_world(size, teams) { )) const [x, y, ..._] = random_choice(available_cells); const orientation = random_choice([ 'n', 'e', 's', 'w' ]); - return [...acc, {...agent, x, y, flags: { ...agent.flags, orientation } }]; + return [...acc, {...agent, x, y, flags: { ...agent.flags, team: team_num, orientation } }]; }, [] )); diff --git a/src/simulation/senses.js b/src/simulation/senses.js index ca07442..9d50a83 100644 --- a/src/simulation/senses.js +++ b/src/simulation/senses.js @@ -152,7 +152,8 @@ function see_agent(viewer, agent) { const see = { size: VIS_WIDTH * VIS_HEIGHT, read: (world, agent) => { - const vision = [...Array(VIS_WIDTH*VIS_HEIGHT).keys()] + const indices = [...Array(VIS_WIDTH*VIS_HEIGHT).keys()] + const vision = indices .map(idx => { const [x, y] = vision_idx_to_world_pos(world, agent, idx); return see_cell(world, x, y); @@ -160,7 +161,8 @@ const see = { const result = world.agents.reduce( (acc, a) => { const idx = world_pos_to_vision_idx(world, agent, a.x, a.y); - if (idx < 0 || idx > VIS_WIDTH*VIS_HEIGHT) { + + if (idx < 0 || idx >= VIS_WIDTH*VIS_HEIGHT) { return acc; } else { acc.splice(idx, 1, see_agent(agent, a)); |