diff options
Diffstat (limited to 'src/simulation/game.js')
-rw-r--r-- | src/simulation/game.js | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/src/simulation/game.js b/src/simulation/game.js index 20c5e4e..f95fbc4 100644 --- a/src/simulation/game.js +++ b/src/simulation/game.js @@ -2,10 +2,13 @@ import { random_choice, apply, shuffle } from '../util.js'; +import { mut_genome_insert, parse_genome } from '../genome/genome.js'; +import { world_update } from '../world/world.js'; import { senses } from './senses.js'; import { actions } from './actions.js'; import { lattice_rules } from './lattice_rules.js'; import { validity } from './validity.js'; +import { postprocess } from './postprocess.js'; function is_wall(size, x, y) { @@ -89,22 +92,22 @@ export function create_world(size, teams) { // games // } +const N_INPUT = senses.reduce((acc, sense) => acc + sense.size, 0); +const N_OUTPUT = actions.reduce((acc, action) => acc + action.size, 0); +const MAX_MUTATIONS = 15; + let agent_id = 0; export function create_agent(genome, n_internal) { return { id: agent_id++, // !!!! side effect !!!! - net: parse_genome, + net: parse_genome(N_INPUT, N_OUTPUT, genome), state: [...Array(n_internal)].map(_ => (2*Math.random()) - 1), } } -const N_INPUT = senses.reduce((acc, sense) => acc + sense.size, 0); -const N_OUTPUT = actions.reduce((acc, action) => acc + action.size, 0); -const MAX_MUTATIONS = 15; - export function create_team(size, genome_size, n_internal) { const genome = apply( @@ -112,6 +115,7 @@ export function create_team(size, genome_size, n_internal) { genome_size, [N_INPUT, n_internal, N_OUTPUT, []], ).slice(-1)[0]; + console.log(N_INPUT, N_OUTPUT, genome); const agents = [...Array(size)].map(_ => create_agent(genome, n_internal)); return { agents, genome, score: 0, games: 0 }; @@ -149,7 +153,7 @@ export function child_team(team, keep=Math.floor(team.size/2)) { export function create_game(teams, team_indices) { - const world = create_world(999, team_indices.map(i => teams[i].agents)); + const world = create_world(100, team_indices.map(i => teams[i].agents)); return { world, team_indices, time: 0 }; } @@ -157,7 +161,7 @@ export function create_game(teams, team_indices) { export function step_game(game) { return { ...game, - world: world_update(world, postprocess), + world: world_update(game.world, postprocess), time: game.time + 1, }; } @@ -202,7 +206,7 @@ function random_indices(teams) { acc.splice(idx, 1); return acc; }, - teams.keys() + [...teams.keys()] ); } @@ -239,7 +243,7 @@ export function update_epoch(epoch) { return [...Array(count > 0 ? count : 1)].map(x => team) }) .flat(); - const new_teams = [...Array(epoch.teams.length] + const new_teams = [...Array(epoch.teams.length)] .reduce((acc) => child_team(random_choice(source_teams)), []); return create_epoch(new_teams); } |