diff --git a/helpers/SimulationManager.js b/helpers/SimulationManager.js index 6744d6d..c62c84e 100644 --- a/helpers/SimulationManager.js +++ b/helpers/SimulationManager.js @@ -2,13 +2,14 @@ import { Car } from "../classes/Car.js"; import { NeuralNetwork } from "../classes/NeuralNetwork.js"; export class SimulationManager { - constructor(canvas, obstacleManager, populationSize, eliteCount, speed, mutationRate) { + constructor(canvas, obstacleManager, populationSize, eliteCount, speed, mutationRate, onGenerationComplete = () => {}) { this.canvas = canvas; this.obstacleManager = obstacleManager; this.populationSize = populationSize; this.eliteCount = eliteCount; this.speed = speed; this.mutationRate = mutationRate; + this.onGenerationComplete = onGenerationComplete; this.generation = 1; // keep track of generations this.CAR_WIDTH = 30; @@ -137,6 +138,10 @@ export class SimulationManager { console.log(`Distance: ${Math.floor(this.distanceTraveled)}`); elites[0].brain.printNetwork(); + if (this.onGenerationComplete) { + this.onGenerationComplete(this.generation, this.distanceTraveled); + } + const newCars = []; const nextGen = this.generation + 1; diff --git a/index.html b/index.html index febe057..87f04ab 100644 --- a/index.html +++ b/index.html @@ -6,7 +6,13 @@
- +