Still cant get neat arena to work
This commit is contained in:
@@ -28,10 +28,14 @@ export interface ConnectionGene {
|
||||
enabled: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Complete genome
|
||||
*/
|
||||
/**
|
||||
* Complete genome
|
||||
*/
|
||||
export interface Genome {
|
||||
id: number;
|
||||
nodes: NodeGene[];
|
||||
connections: ConnectionGene[];
|
||||
fitness: number;
|
||||
@@ -75,6 +79,8 @@ export class InnovationTracker {
|
||||
}
|
||||
}
|
||||
|
||||
let nextGenomeId = 0;
|
||||
|
||||
/**
|
||||
* Create a minimal genome with only input and output nodes, fully connected
|
||||
*/
|
||||
@@ -87,7 +93,8 @@ export function createMinimalGenome(
|
||||
const connections: ConnectionGene[] = [];
|
||||
|
||||
// Create input nodes (IDs 0 to inputCount-1)
|
||||
for (let i = 0; i < inputCount; i++) {
|
||||
// PLUS one extra for Bias
|
||||
for (let i = 0; i < inputCount + 1; i++) {
|
||||
nodes.push({
|
||||
id: i,
|
||||
type: 'input',
|
||||
@@ -95,34 +102,47 @@ export function createMinimalGenome(
|
||||
});
|
||||
}
|
||||
|
||||
// Create output nodes (IDs starting from inputCount)
|
||||
// Create output nodes (IDs starting from inputCount + 1)
|
||||
// Fix: Bias node uses ID `inputCount`, so outputs must start at `inputCount + 1`
|
||||
for (let i = 0; i < outputCount; i++) {
|
||||
nodes.push({
|
||||
id: inputCount + i,
|
||||
id: inputCount + 1 + i,
|
||||
type: 'output',
|
||||
activation: 'tanh',
|
||||
});
|
||||
}
|
||||
|
||||
// Create fully connected minimal genome
|
||||
for (let i = 0; i < inputCount; i++) {
|
||||
const inputNode = i; // Assuming inputNode refers to the ID
|
||||
// Iterate through all inputs INCLUDING Bias
|
||||
for (let i = 0; i < inputCount + 1; i++) {
|
||||
const inputNode = i;
|
||||
|
||||
for (let o = 0; o < outputCount; o++) {
|
||||
const outputNode = inputCount + o; // Assuming outputNode refers to the ID
|
||||
const outputNode = inputCount + 1 + o; // target the shifted output IDs
|
||||
const innovation = innovationTracker.getInnovation(inputNode, outputNode);
|
||||
|
||||
let weight = (Math.random() * 2.0) - 1.0;
|
||||
|
||||
// FORCE AGGRESSION:
|
||||
// If connection is from BIAS node (index == inputCount) TO SHOOT node (index 3 of output)
|
||||
// Warning: Output indices are 0..4 relative to output block.
|
||||
// Shoot is 4th output (moveX, moveY, turn, shoot, reserved).
|
||||
if (inputNode === inputCount && o === 3) {
|
||||
weight = 1.0 + Math.random(); // Range [1.0, 2.0] -> Strong Positive Bias
|
||||
}
|
||||
|
||||
connections.push({
|
||||
innovation,
|
||||
from: inputNode,
|
||||
to: outputNode,
|
||||
weight: (Math.random() * 4) - 2, // Random weight in [-2, 2] for initial diversity
|
||||
weight,
|
||||
enabled: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
id: nextGenomeId++,
|
||||
nodes,
|
||||
connections,
|
||||
fitness: 0,
|
||||
@@ -134,6 +154,7 @@ export function createMinimalGenome(
|
||||
*/
|
||||
export function cloneGenome(genome: Genome): Genome {
|
||||
return {
|
||||
id: nextGenomeId++,
|
||||
nodes: genome.nodes.map(n => ({ ...n })),
|
||||
connections: genome.connections.map(c => ({ ...c })),
|
||||
fitness: genome.fitness,
|
||||
|
||||
Reference in New Issue
Block a user