From e7eb6a78e165c2103323baa9bd6cbdaf7444c17d Mon Sep 17 00:00:00 2001 From: sanine Date: Fri, 10 Nov 2023 20:39:44 -0600 Subject: add trigger action --- src/simulation/actions.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/simulation/actions.js') diff --git a/src/simulation/actions.js b/src/simulation/actions.js index 8a4e8f0..dd7c4e6 100644 --- a/src/simulation/actions.js +++ b/src/simulation/actions.js @@ -97,8 +97,26 @@ const place = { }; +const trigger = { + 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]; + return [ + { lattice_changes: [{ + x: agent.x + dx, y: agent.y + dy, + from: 'mutable', to: 'active', + flags: { emit: [1, 0, 0, 0, 0, 0, 0, 0] }, + }]} + ]; + } + }, +}; export const actions = [ - move_forward, move_backward, turn_left, turn_right, place, + move_forward, move_backward, turn_left, turn_right, + place, trigger, ]; -- cgit v1.2.1