summaryrefslogtreecommitdiff
path: root/src/simulation
diff options
context:
space:
mode:
Diffstat (limited to 'src/simulation')
-rw-r--r--src/simulation/actions.js1
-rw-r--r--src/simulation/game.js21
2 files changed, 14 insertions, 8 deletions
diff --git a/src/simulation/actions.js b/src/simulation/actions.js
index 4ee17d8..3b3e942 100644
--- a/src/simulation/actions.js
+++ b/src/simulation/actions.js
@@ -8,6 +8,7 @@ const move_forward = {
propose: (world, agent, head) => {
if (agent.flags.frozen === true) { return []; }
if (head[0] > threshold) {
+ console.log('move forward');
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 [{
diff --git a/src/simulation/game.js b/src/simulation/game.js
index 05ac4a1..978289d 100644
--- a/src/simulation/game.js
+++ b/src/simulation/game.js
@@ -49,7 +49,11 @@ export function setup_board(size) {
return { type: 'immutable', flags: {} };
} else {
const team = get_team(size, x, y);
- return { type: 'empty', flags: { team } };
+ if (Math.random() > 0.95 && get_team(size, x, y) === undefined) {
+ return { type: 'flag', flags: { team } };
+ } else {
+ return { type: 'empty', flags: { team } };
+ }
}
}));
return lattice;
@@ -152,8 +156,8 @@ export function child_team(team, keep=Math.floor(team.size/2)) {
// }
-export function create_game(teams, team_indices) {
- const world = create_world(100, team_indices.map(i => teams[i].agents));
+export function create_game(size, teams, team_indices) {
+ const world = create_world(size, team_indices.map(i => teams[i].agents));
return { world, team_indices, time: 0 };
}
@@ -211,17 +215,18 @@ function random_indices(teams) {
}
let epoch_num = 0;
-export function create_epoch(teams) {
+export function create_epoch(size, teams) {
return {
- game: create_game(teams, random_indices(teams)),
+ game: create_game(size, teams, random_indices(teams)),
time: 0,
epoch: epoch_num++, // !!!! side effects !!!!
+ size,
teams,
}
}
-const GAME_STEPS = 5000
+const GAME_STEPS = 10000
const EPOCH_STEPS = 200
export function update_epoch(epoch) {
@@ -231,7 +236,7 @@ export function update_epoch(epoch) {
return {
...epoch,
teams: finish_game(epoch.teams, epoch.game),
- game: create_game(epoch.teams, random_indices(epoch.teams)),
+ game: create_game(size, epoch.teams, random_indices(epoch.teams)),
time: epoch.time+1
};
} else {
@@ -245,6 +250,6 @@ export function update_epoch(epoch) {
.flat();
const new_teams = [...Array(epoch.teams.length)]
.reduce((acc) => child_team(random_choice(source_teams)), []);
- return create_epoch(new_teams);
+ return create_epoch(epoch.size, new_teams);
}
}