Skip to content

Instantly share code, notes, and snippets.

@LiorB-D
Created July 15, 2022 10:51
Show Gist options
  • Save LiorB-D/5960e84537c09fd85f856ed624e7e364 to your computer and use it in GitHub Desktop.
Save LiorB-D/5960e84537c09fd85f856ed624e7e364 to your computer and use it in GitHub Desktop.
function endGen() {
let totalFitness = 0
bestOfGen = 0
// Calculate total fitness and find highest performing car
cars.forEach((car, ind) => {
car.dead = true
totalFitness += car.fitness
if(car.fitness > bestOfGen) {bestOfGen = car.fitness}
})
//Update highest score if applicable
if(bestOfGen > topFitnessScore) {
topFitnessScore = bestOfGen
}
return totalFitness
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment