summaryrefslogtreecommitdiff
path: root/src/simulation/actions.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/simulation/actions.js')
-rw-r--r--src/simulation/actions.js260
1 files changed, 0 insertions, 260 deletions
diff --git a/src/simulation/actions.js b/src/simulation/actions.js
deleted file mode 100644
index ad08572..0000000
--- a/src/simulation/actions.js
+++ /dev/null
@@ -1,260 +0,0 @@
-'use strict';
-
-const threshold = 0.5;
-
-
-const move_forward = {
- size: 1,
- propose: (world, agent, head) => {
- if (agent.flags.frozen === true) { return []; }
- if (head[0] > threshold) {
- console.log('move forward');
- console.log(agent.id, agent.x, agent.y);
- 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 (agent.flags.frozen === true) { return []; }
- if (head[0] > threshold) {
- console.log('move backward');
- 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 (agent.flags.frozen === true) { return []; }
- if (head[0] > threshold) {
- console.log('turn left');
- 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 (agent.flags.frozen === true) { return []; }
- if (head[0] > threshold) {
- console.log('turn right');
- 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 },
- }]
- }];
- }
- },
-};
-
-
-const unfreeze = {
- 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) { return []; }
- return [
- { agent_changes: [{
- agent_id: target.id,
- flags: { frozen: false, emit: [0, 1, 0, 0, 0, 0, 0, 0] },
- }]}
- ];
- }
- },
-};
-
-
-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 },
- },
- ],
- }];
- }
- }
- },
-};
-
-
-const drop_flag = {
- size: 1,
- propose: (world, agent, head) => {
- if (head[0] < threshold) { return []; }
- else if (!agent.flags.flag) { 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: 'flag',
- flags: { emit: [ 0, 0, -1, 0, 0, 0, 0, 0 ] },
- }],
- agent_changes: [{
- agent_id: agent.id,
- flags: { flag: false },
- }],
- }
- ];
- }
- },
-};
-
-
-const speak = {
- size: 8,
- propose: (world, agent, head) => {
- return [
- {
- agent_changes: [{
- agent_id: agent.id,
- flags: { emit: head },
- }],
- },
- ];
- },
-};
-
-
-export const actions = [
- move_forward, /*move_backward, */turn_left, turn_right,
- place, trigger, pretend_frozen, unfreeze, take_flag, drop_flag,
- speak,
-];