Created
July 15, 2022 10:51
-
-
Save LiorB-D/5960e84537c09fd85f856ed624e7e364 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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