From a85f61cef6aef51bf6983f98020f3284aeb5020d Mon Sep 17 00:00:00 2001 From: sanine Date: Fri, 10 Nov 2023 16:57:23 -0600 Subject: implement move_forward action --- src/simulation/actions.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/simulation/actions.js (limited to 'src/simulation/actions.js') diff --git a/src/simulation/actions.js b/src/simulation/actions.js new file mode 100644 index 0000000..40545c5 --- /dev/null +++ b/src/simulation/actions.js @@ -0,0 +1,28 @@ +'use strict'; + +const threshold = 0.5; + + +const move_forward = { + size: 1, + propose: (agent, head) => { + if (head[0] > threshold) { + 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 [{ + agent_changes: [{ + agent_id: agent.id, + x: agent.x + dx, + y: agent.y + dy, + }], + }]; + } else { + return []; + } + }, +}; + + +export const actions = [ + move_forward, +]; -- cgit v1.2.1