'use strict'; const threshold = 0.5; const move_forward = { size: 1, propose: (world, 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 move_backward = { size: 1, propose: (world, 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: (world, 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 []; } }, }; const turn_right = { size: 1, propose: (world, agent, head) => { if (head[0] > threshold) { const orientation = { n: 'e', e: 's', s: 'w', w: 'n' }[agent.flags.orientation]; return [{ agent_changes: [{ agent_id: agent.id, flags: { orientation }, }], }]; } else { return []; } }, }; const place = { 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: 'empty', to: 'mutable', flags: { emit: [1, 0, 0, 0, 0, 0, 0, 0] }, }]} ]; } }, }; 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] }, }]} ]; } }, }; 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, pretend_frozen, ];