summaryrefslogtreecommitdiff
path: root/src/simulation/actions.js
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-11-10 21:53:01 -0600
committersanine <sanine.not@pm.me>2023-11-10 21:53:01 -0600
commit86e1ab63d25ed6387c3bc4f5c07e9e041a1c7823 (patch)
tree09501817f06a09ccf38ce0223d598626a9a5b061 /src/simulation/actions.js
parent8252de1deb1a677a71108f6c5f8705d7c04a63fe (diff)
implement take_flag action
Diffstat (limited to 'src/simulation/actions.js')
-rw-r--r--src/simulation/actions.js45
1 files changed, 44 insertions, 1 deletions
diff --git a/src/simulation/actions.js b/src/simulation/actions.js
index 62a8395..6497917 100644
--- a/src/simulation/actions.js
+++ b/src/simulation/actions.js
@@ -159,7 +159,50 @@ const unfreeze = {
};
+const take_flag = {
+ size: 1,
+ propose: (world, agent, head) => {
+ if (head[0] < threshold) { 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];
+ const target = world.agents.filter(
+ a => a.x === agent.x+dx && a.y === agent.y+dy
+ )[0];
+ if (target === undefined || !target.flags.flag) {
+ return [
+ {
+ lattice_changes: [{
+ x: agent.x + dx, y: agent.y + dy,
+ from: 'flag', to: 'empty',
+ flags: { emit: [ 0, 0, 1, 0, 0, 0, 0, 0 ] },
+ }],
+ agent_changes: [{
+ agent_id: agent.id,
+ flags: { flag: true },
+ }],
+ }
+ ];
+ } else {
+ return [{
+ agent_changes: [
+ {
+ agent_id: target.id,
+ flags: { flag: false },
+ },
+ {
+ agent_id: agent.id,
+ flags: { flag: true },
+ },
+ ],
+ }];
+ }
+ }
+ },
+};
+
+
export const actions = [
move_forward, move_backward, turn_left, turn_right,
- place, trigger, pretend_frozen, unfreeze,
+ place, trigger, pretend_frozen, unfreeze, take_flag,
];