Still cant get neat arena to work
This commit is contained in:
@@ -123,9 +123,8 @@ export default function NeatArena() {
|
||||
};
|
||||
}, [mapSeed]);
|
||||
|
||||
// Exhibition match loop (visualizing champion vs baseline)
|
||||
// Exhibition match loop (visualizing best vs second-best AI)
|
||||
useEffect(() => {
|
||||
if (isTraining) return; // Don't run exhibition during training
|
||||
if (!phaserGameRef.current) return;
|
||||
|
||||
const interval = setInterval(() => {
|
||||
@@ -138,18 +137,15 @@ export default function NeatArena() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Agent 0: Imported genome, current gen best, or spinner
|
||||
// Get best and second-best genomes
|
||||
const sortedGenomes = [...population.genomes].sort((a, b) => b.fitness - a.fitness);
|
||||
const genome0 = importedGenome || sortedGenomes[0] || null;
|
||||
const genome1 = sortedGenomes.length > 1 ? sortedGenomes[1] : null;
|
||||
|
||||
// Agent 0: Best AI
|
||||
let action0: AgentAction;
|
||||
|
||||
// Priority: imported > current gen best > all-time best > spinner
|
||||
const currentGenBest = population.genomes.length > 0
|
||||
? population.genomes.reduce((best, g) => g.fitness > best.fitness ? g : best)
|
||||
: null;
|
||||
|
||||
const genomeToUse = importedGenome || currentGenBest || population.bestGenomeEver;
|
||||
|
||||
if (genomeToUse) {
|
||||
const network = createNetwork(genomeToUse);
|
||||
if (genome0) {
|
||||
const network = createNetwork(genome0);
|
||||
const obs = generateObservation(0, sim);
|
||||
const inputs = observationToInputs(obs);
|
||||
const outputs = network.activate(inputs);
|
||||
@@ -164,8 +160,23 @@ export default function NeatArena() {
|
||||
action0 = spinnerBotAction();
|
||||
}
|
||||
|
||||
// Agent 1: Spinner bot
|
||||
const action1 = spinnerBotAction();
|
||||
// Agent 1: Second-best AI (or spinner if not enough genomes)
|
||||
let action1: AgentAction;
|
||||
if (genome1) {
|
||||
const network = createNetwork(genome1);
|
||||
const obs = generateObservation(1, sim);
|
||||
const inputs = observationToInputs(obs);
|
||||
const outputs = network.activate(inputs);
|
||||
|
||||
action1 = {
|
||||
moveX: outputs[0],
|
||||
moveY: outputs[1],
|
||||
turn: outputs[2],
|
||||
shoot: outputs[3],
|
||||
};
|
||||
} else {
|
||||
action1 = spinnerBotAction();
|
||||
}
|
||||
|
||||
simulationRef.current = stepSimulation(sim, [action0, action1]);
|
||||
|
||||
@@ -178,7 +189,7 @@ export default function NeatArena() {
|
||||
}, 1000 / 30);
|
||||
|
||||
return () => clearInterval(interval);
|
||||
}, [isTraining, showRays, mapSeed, population.bestGenomeEver, importedGenome]);
|
||||
}, [showRays, mapSeed, population.genomes, importedGenome]);
|
||||
|
||||
const handleReset = useCallback(() => {
|
||||
setIsTraining(false);
|
||||
@@ -269,10 +280,10 @@ export default function NeatArena() {
|
||||
{isTraining
|
||||
? '🟢 Training in background worker...'
|
||||
: importedGenome
|
||||
? '🎮 Watching imported champion vs Spinner bot'
|
||||
: population.bestGenomeEver
|
||||
? '🎮 Watching champion vs Spinner bot'
|
||||
: '⚪ No champion yet'}
|
||||
? '🎮 Watching imported champion vs Gen best'
|
||||
: population.genomes.length > 1
|
||||
? `🎮 Watching Gen ${stats.generation}: Best vs 2nd-Best AI`
|
||||
: '⚪ Need at least 2 genomes for exhibition'}
|
||||
</p>
|
||||
</section>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user