diff options
author | sanine <sanine.not@pm.me> | 2023-11-12 13:59:50 -0600 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2023-11-12 13:59:50 -0600 |
commit | 95fd952b6d4c496efc0e6236ba2acfcbbeee8ed9 (patch) | |
tree | 2fd28076f9fe119481dcb439865b4076d00fc692 /src/simulation | |
parent | 22fe18beac4459427c2b40499afafc7c5c868691 (diff) |
add visualization
Diffstat (limited to 'src/simulation')
-rw-r--r-- | src/simulation/actions.js | 1 | ||||
-rw-r--r-- | src/simulation/game.js | 21 |
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); } } |