diff options
-rw-r--r-- | src/simulation/actions.js | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/src/simulation/actions.js b/src/simulation/actions.js index 6497917..78345ce 100644 --- a/src/simulation/actions.js +++ b/src/simulation/actions.js @@ -22,6 +22,7 @@ const move_forward = { }, }; + const move_backward = { size: 1, propose: (world, agent, head) => { @@ -202,7 +203,49 @@ const take_flag = { }; +const drop_flag = { + size: 1, + propose: (world, agent, head) => { + if (head[0] < threshold) { return []; } + else if (!agent.flags.flag) { return []; } + else { + 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 [ + { + lattice_changes: [{ + x: agent.x + dx, y: agent.y + dy, + from: 'empty', to: 'flag', + flags: { emit: [ 0, 0, -1, 0, 0, 0, 0, 0 ] }, + }], + agent_changes: [{ + agent_id: agent.id, + flags: { flag: false }, + }], + } + ]; + } + }, +}; + + +const speak = { + size: 8, + propose: (world, agent, head) => { + return [ + { + agent_changes: [{ + agent_id: agent.id, + flags: { emit: head }, + }], + }, + ]; + }, +}; + + export const actions = [ move_forward, move_backward, turn_left, turn_right, - place, trigger, pretend_frozen, unfreeze, take_flag, + place, trigger, pretend_frozen, unfreeze, take_flag, drop_flag, + speak, ]; |