Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ let inside = [];
let outside = [];
let checkpoints = [];

// around 5-6 successfully completed rounds will make the fitness of 500+
// so maxFitness is set to 500
// thus the changeMap will flag becomes true and we will create new map
// when any of the particle completes multiple rounds in current map
// this will help to make the current generation to work on new map
// and generalize to variety of maps
const maxFitness = 500;
let changeMap = false;

function buildTrack() {
checkpoints = [];
inside = [];
Expand Down Expand Up @@ -104,6 +113,21 @@ function draw() {
if (particle.dead || particle.finished) {
savedParticles.push(population.splice(i, 1)[0]);
}

if (!changeMap && particle.fitness > maxFitness) {
changeMap = true;
}
}

if (population.length !== 0 && changeMap) {
for (let i = population.length - 1; i >= 0; i--) {
savedParticles.push(population.splice(i, 1)[0]);
}

buildTrack();
nextGeneration();
generationCount++;
changeMap=false;
}

if (population.length == 0) {
Expand Down