diff options
author | sanine <sanine.not@pm.me> | 2023-11-10 16:57:23 -0600 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2023-11-10 16:57:23 -0600 |
commit | a85f61cef6aef51bf6983f98020f3284aeb5020d (patch) | |
tree | f86af3b7f9b63914079d0ff8c55b8f17b47df5fd /src/simulation/actions.js | |
parent | 3f8b3ea65df956c23b397913561cc8ebe5403c6e (diff) |
implement move_forward action
Diffstat (limited to 'src/simulation/actions.js')
-rw-r--r-- | src/simulation/actions.js | 28 |
1 files changed, 28 insertions, 0 deletions
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, +]; |