diff options
author | sanine <sanine.not@pm.me> | 2023-11-11 13:12:39 -0600 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2023-11-11 13:12:39 -0600 |
commit | 5535ff5b2894e97b5387b52caee6078d461c2210 (patch) | |
tree | 263018c6e1ab146acc3004a0618f5ca3ee67b3a9 /src/simulation | |
parent | 86e1ab63d25ed6387c3bc4f5c07e9e041a1c7823 (diff) |
add drop_flag and speak actions
Diffstat (limited to 'src/simulation')
-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, ]; |