diff options
author | sanine <sanine.not@pm.me> | 2023-11-12 15:18:29 -0600 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2023-11-12 15:18:29 -0600 |
commit | 7825b92ce3be95a0ce1dfea9388adbaadce83b1f (patch) | |
tree | eb1e38561e3aba4b890e666e04d46e4de499658e /src | |
parent | 95fd952b6d4c496efc0e6236ba2acfcbbeee8ed9 (diff) |
fix bugs
Diffstat (limited to 'src')
-rw-r--r-- | src/mind/topology.js | 9 | ||||
-rw-r--r-- | src/simulation/actions.js | 6 | ||||
-rw-r--r-- | src/simulation/senses.js | 6 | ||||
-rw-r--r-- | src/ui/index.js | 5 | ||||
-rw-r--r-- | src/world/agent.js | 2 | ||||
-rw-r--r-- | src/world/proposal.js | 3 |
6 files changed, 23 insertions, 8 deletions
diff --git a/src/mind/topology.js b/src/mind/topology.js index 9f2569d..946dd86 100644 --- a/src/mind/topology.js +++ b/src/mind/topology.js @@ -131,6 +131,13 @@ function get_value(n, index, input, prev, cache) { const sum = values // compute the weighted sum of the values .reduce((acc, x, i) => acc + (weight[i] * x), 0); + if (sum !== sum) { // NaN test + console.log(n); + console.log(sources); + console.log(input); + throw new Error(`failed to get output for index ${index}`); + } + // compute result const value = Math.tanh(sum); @@ -139,7 +146,7 @@ function get_value(n, index, input, prev, cache) { if (cache !== undefined) { cache[index] = value; } - + return value; } diff --git a/src/simulation/actions.js b/src/simulation/actions.js index 3b3e942..ad08572 100644 --- a/src/simulation/actions.js +++ b/src/simulation/actions.js @@ -9,6 +9,7 @@ const move_forward = { if (agent.flags.frozen === true) { return []; } if (head[0] > threshold) { console.log('move forward'); + console.log(agent.id, agent.x, agent.y); const dx = { n: 0, e: 1, s: 0, w: -1 }[agent.flags.orientation]; const dy = { n: -1, e: 0, s: 1, w: 0 }[agent.flags.orientation]; return [{ @@ -30,6 +31,7 @@ const move_backward = { propose: (world, agent, head) => { if (agent.flags.frozen === true) { return []; } if (head[0] > threshold) { + console.log('move backward'); const dx = { n: 0, e: 1, s: 0, w: -1 }[agent.flags.orientation]; const dy = { n: -1, e: 0, s: 1, w: 0 }[agent.flags.orientation]; return [{ @@ -51,6 +53,7 @@ const turn_left = { propose: (world, agent, head) => { if (agent.flags.frozen === true) { return []; } if (head[0] > threshold) { + console.log('turn left'); const orientation = { n: 'w', e: 'n', s: 'e', w: 's' }[agent.flags.orientation]; return [{ agent_changes: [{ @@ -70,6 +73,7 @@ const turn_right = { propose: (world, agent, head) => { if (agent.flags.frozen === true) { return []; } if (head[0] > threshold) { + console.log('turn right'); const orientation = { n: 'e', e: 's', s: 'w', w: 'n' }[agent.flags.orientation]; return [{ agent_changes: [{ @@ -250,7 +254,7 @@ const speak = { export const actions = [ - move_forward, move_backward, turn_left, turn_right, + move_forward, /*move_backward, */turn_left, turn_right, place, trigger, pretend_frozen, unfreeze, take_flag, drop_flag, speak, ]; diff --git a/src/simulation/senses.js b/src/simulation/senses.js index 9d50a83..970f86b 100644 --- a/src/simulation/senses.js +++ b/src/simulation/senses.js @@ -150,7 +150,7 @@ function see_agent(viewer, agent) { const see = { - size: VIS_WIDTH * VIS_HEIGHT, + size: 3*VIS_WIDTH * VIS_HEIGHT, read: (world, agent) => { const indices = [...Array(VIS_WIDTH*VIS_HEIGHT).keys()] const vision = indices @@ -171,12 +171,12 @@ const see = { }, vision ); - return result; + return result.flat(); }, }; export const senses = [ - frozen, hear, see, + frozen, hear, see, { size: 1, read: () => [1] }, ]; diff --git a/src/ui/index.js b/src/ui/index.js index b710b48..01068cb 100644 --- a/src/ui/index.js +++ b/src/ui/index.js @@ -2,8 +2,11 @@ import { draw } from './canvas.js'; import { create_team, create_epoch, update_epoch } from '../simulation/game.js'; -const start_teams = [...Array(5)].map(x => create_team(8, 50, 50)); +console.log("generating agents..."); +const start_teams = [...Array(4)].map(x => create_team(2, 400, 50)); +console.log("creating epoch..."); let epoch = create_epoch(60, start_teams); +console.log("ready!"); function draw_cell(ctx, x, y, cell) { diff --git a/src/world/agent.js b/src/world/agent.js index dbfdf5d..2be7420 100644 --- a/src/world/agent.js +++ b/src/world/agent.js @@ -7,7 +7,7 @@ import { proposal_merge } from './proposal.js'; export function agent_decide(world, agent, senses, actions) { const inputs = senses.map(s => sense_read(world, agent, s)).flat(); const [result, state] = agent.net.compute(inputs, agent.state); - console.log(agent, result); + console.log(result, state); const new_agent = { ...agent, state }; const [proposals, _] = actions.reduce( diff --git a/src/world/proposal.js b/src/world/proposal.js index 0969540..8baca06 100644 --- a/src/world/proposal.js +++ b/src/world/proposal.js @@ -57,6 +57,7 @@ import { pairs, deepEqual } from '../util.js'; // check that two flags objects are compatible // flags are considered compatible if they do not have any common keys with different values function flags_compatible(a, b) { + if (a === undefined || b === undefined) { return true; } const keys = [...new Set(Object.keys(a).concat(Object.keys(b)))]; return keys.reduce( (acc, key) => { @@ -80,7 +81,7 @@ function lattice_change_conflict(a, b) { if ( a.x === b.x && a.y === b.y && - (a.to != b.to || !flags_compatible(a.flags || {}, b.flags || {})) + (a.to != b.to || !flags_compatible((a.flags || {}), (b.flags || {}))) ) { // conflict! return [true, false]; |