diff options
-rw-r--r-- | src/simulation/actions.js | 25 | ||||
-rw-r--r-- | src/simulation/actions.test.js | 20 |
2 files changed, 43 insertions, 2 deletions
diff --git a/src/simulation/actions.js b/src/simulation/actions.js index dd7c4e6..e389518 100644 --- a/src/simulation/actions.js +++ b/src/simulation/actions.js @@ -100,7 +100,7 @@ const place = { const trigger = { size: 1, propose: (world, agent, head) => { - if (head[0] < threshold) { return []; } + 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]; @@ -116,7 +116,28 @@ const trigger = { }; +const pretend_frozen = { + size: 1, + propose: (world, agent, head) => { + if (head[0] < threshold) { return [{ + agent_changes: [{ + agent_id: agent.id, + flags: { pretend_frozen: false }, + }], + }]; } + else { + return [{ + agent_changes: [{ + agent_id: agent.id, + flags: { pretend_frozen: true }, + }] + }]; + } + }, +}; + + export const actions = [ move_forward, move_backward, turn_left, turn_right, - place, trigger, + place, trigger, pretend_frozen, ]; diff --git a/src/simulation/actions.test.js b/src/simulation/actions.test.js index 1ebe9a9..43ad23c 100644 --- a/src/simulation/actions.test.js +++ b/src/simulation/actions.test.js @@ -7,6 +7,7 @@ const [ move_forward, move_backward, turn_left, turn_right, place, trigger, + pretend_frozen, ...rest ] = actions; @@ -197,3 +198,22 @@ test("trigger", () => { expect(trigger.propose(null, e, [0])).toEqual([]); expect(trigger.propose(null, w, [-1])).toEqual([]); }); + + +test("pretend frozen", () => { + const agent = { id: 2, x: 0, y: 0, flags: { orientation: 'n' } }; + + expect(pretend_frozen.propose(null, agent, [1])).toEqual([{ + agent_changes: [{ + agent_id: 2, + flags: { pretend_frozen: true }, + }] + }]); + + expect(pretend_frozen.propose(null, agent, [0])).toEqual([{ + agent_changes: [{ + agent_id: 2, + flags: { pretend_frozen: false }, + }] + }]); +}); |