From 5535ff5b2894e97b5387b52caee6078d461c2210 Mon Sep 17 00:00:00 2001 From: sanine Date: Sat, 11 Nov 2023 13:12:39 -0600 Subject: add drop_flag and speak actions --- src/simulation/actions.js | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) (limited to 'src/simulation/actions.js') 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, ]; -- cgit v1.2.1