summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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(