diff --git a/src/site/snake/canvas.ts b/src/site/snake/canvas.ts index e3ef837..575da20 100644 --- a/src/site/snake/canvas.ts +++ b/src/site/snake/canvas.ts @@ -135,6 +135,8 @@ export default function runCanvas(canvas: HTMLCanvasElement, pipeRef: MutableRef const STARVE_STEPS = BOARD_SQUARES * 6; // neat configuration ------------------------------------------------------ + // TODO: this configuration is not learning + // figure out why, maybe scoring is not proper -- or speciation is too forced const FC: FertilityConfig = { fertile_threshold: 0.6, champion_min_species_size: 3, diff --git a/src/site/snake/neat-snake-brain.ts b/src/site/snake/neat-snake-brain.ts index fac15bc..3586494 100644 --- a/src/site/snake/neat-snake-brain.ts +++ b/src/site/snake/neat-snake-brain.ts @@ -25,10 +25,10 @@ const FEATURES = { HEAD_Y: 'HEAD_Y', APPLE_REL_X: 'APPLE_REL_X', APPLE_REL_Y: 'APPLE_REL_Y', - // TAIL_ABOVE: 'TAIL_ABOVE', - // TAIL_BELOW: 'TAIL_BELOW', - // TAIL_LEFT: 'TAIL_LEFT', - // TAIL_RIGHT: 'TAIL_RIGHT', + TAIL_ABOVE: 'TAIL_ABOVE', + TAIL_BELOW: 'TAIL_BELOW', + TAIL_LEFT: 'TAIL_LEFT', + TAIL_RIGHT: 'TAIL_RIGHT', }; const OUTPUTS = { U: 'U', @@ -43,10 +43,10 @@ const _BASE_GENOME_SNAKE_BRAIN_NEAT_EDGES = completeBipartiteEdges( FEATURES.HEAD_Y, FEATURES.APPLE_REL_X, FEATURES.APPLE_REL_Y, - // FEATURES.TAIL_ABOVE, - // FEATURES.TAIL_BELOW, - // FEATURES.TAIL_LEFT, - // FEATURES.TAIL_RIGHT, + FEATURES.TAIL_ABOVE, + FEATURES.TAIL_BELOW, + FEATURES.TAIL_LEFT, + FEATURES.TAIL_RIGHT, ], [OUTPUTS.U, OUTPUTS.D, OUTPUTS.L, OUTPUTS.R], ); @@ -108,10 +108,10 @@ export class NEATSnakeBrain { act.set(FEATURES.HEAD_Y, head.y); act.set(FEATURES.APPLE_REL_X, appleRel.x); act.set(FEATURES.APPLE_REL_Y, appleRel.y); - // act.set(FEATURES.TAIL_ABOVE, Math.max(...above, BOARD_SQUARES)); - // act.set(FEATURES.TAIL_BELOW, Math.max(...below, BOARD_SQUARES)); - // act.set(FEATURES.TAIL_LEFT, Math.max(...left, BOARD_SQUARES)); - // act.set(FEATURES.TAIL_RIGHT, Math.max(...right, BOARD_SQUARES)); + act.set(FEATURES.TAIL_ABOVE, Math.max(...above, BOARD_SQUARES)); + act.set(FEATURES.TAIL_BELOW, Math.max(...below, BOARD_SQUARES)); + act.set(FEATURES.TAIL_LEFT, Math.max(...left, BOARD_SQUARES)); + act.set(FEATURES.TAIL_RIGHT, Math.max(...right, BOARD_SQUARES)); this.brain.think(act); diff --git a/src/site/snake/neat.ts b/src/site/snake/neat.ts index 8db6e49..a8aa9de 100644 --- a/src/site/snake/neat.ts +++ b/src/site/snake/neat.ts @@ -594,18 +594,12 @@ export function mutate(genome: Genome, config: MutateConfig): Genome { if (Math.random() < new_connection_rate) { // create a new connection between two *previously unconnected* nodes const options = findAcyclicInternalNewConns(newGenome); - if (options.length === 0) { - // TODO: remove this warn once this starts working - // this is mostly a sanity check / useful for metrics - console.warn('could not find a valid new connection!'); - } else { + if (options.length > 0) { // choose a random connection const newConn = randchoice(options); const newGene = mutateNewConn(newConn, assign_mag * randomNegPos()); newGenome.push(newGene); } - - findAcyclicInternalNewConns(newGenome); } return newGenome;