summaryrefslogtreecommitdiff
path: root/src/simulation/actions.js
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-11-10 17:10:46 -0600
committersanine <sanine.not@pm.me>2023-11-10 17:10:46 -0600
commitc9e241e3ffed2131c240607b8dfb36510217dc88 (patch)
tree66ebca480c8bff0381a1e14fae139511422f74aa /src/simulation/actions.js
parenta85f61cef6aef51bf6983f98020f3284aeb5020d (diff)
implement move_backward and turn_left
Diffstat (limited to 'src/simulation/actions.js')
-rw-r--r--src/simulation/actions.js42
1 files changed, 41 insertions, 1 deletions
diff --git a/src/simulation/actions.js b/src/simulation/actions.js
index 40545c5..a925867 100644
--- a/src/simulation/actions.js
+++ b/src/simulation/actions.js
@@ -22,7 +22,47 @@ const move_forward = {
},
};
+const move_backward = {
+ 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 [];
+ }
+ },
+};
+
+
+const turn_left = {
+ size: 1,
+ propose: (agent, head) => {
+ if (head[0] > threshold) {
+ const orientation = { n: 'w', e: 'n', s: 'e', w: 's' }[agent.flags.orientation];
+ return [{
+ agent_changes: [{
+ agent_id: agent.id,
+ flags: { orientation },
+ }],
+ }];
+ } else {
+ return [];
+ }
+ },
+};
+
+
+
+
export const actions = [
- move_forward,
+ move_forward, move_backward, turn_left,
];