summaryrefslogtreecommitdiff
path: root/src/simulation/game.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/simulation/game.js')
-rw-r--r--src/simulation/game.js21
1 files changed, 13 insertions, 8 deletions
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);
}
}