enable full sized snake genome

This commit is contained in:
Michael Peters 2024-09-04 21:04:47 -07:00
parent b33ffc3baa
commit a69af98250
3 changed files with 15 additions and 19 deletions

View File

@ -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,

View File

@ -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);

View File

@ -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;