File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -26,6 +26,15 @@ let inside = [];
2626let outside = [ ] ;
2727let checkpoints = [ ] ;
2828
29+ // around 5-6 successfully completed rounds will make the fitness of 500+
30+ // so maxFitness is set to 500
31+ // thus the changeMap will flag becomes true and we will create new map
32+ // when any of the particle completes multiple rounds in current map
33+ // this will help to make the current generation to work on new map
34+ // and generalize to variety of maps
35+ const maxFitness = 500 ;
36+ let changeMap = false ;
37+
2938function buildTrack ( ) {
3039 checkpoints = [ ] ;
3140 inside = [ ] ;
@@ -104,6 +113,21 @@ function draw() {
104113 if ( particle . dead || particle . finished ) {
105114 savedParticles . push ( population . splice ( i , 1 ) [ 0 ] ) ;
106115 }
116+
117+ if ( ! changeMap && particle . fitness > maxFitness ) {
118+ changeMap = true ;
119+ }
120+ }
121+
122+ if ( population . length !== 0 && changeMap ) {
123+ for ( let i = population . length - 1 ; i >= 0 ; i -- ) {
124+ savedParticles . push ( population . splice ( i , 1 ) [ 0 ] ) ;
125+ }
126+
127+ buildTrack ( ) ;
128+ nextGeneration ( ) ;
129+ generationCount ++ ;
130+ changeMap = false ;
107131 }
108132
109133 if ( population . length == 0 ) {
You can’t perform that action at this time.
0 commit comments