()
| 111 | } |
| 112 | |
| 113 | NaturalSelection() { |
| 114 | let nextGen = []; |
| 115 | this.SetBestPlayer(); |
| 116 | this.CalculateFitnessSum(); |
| 117 | |
| 118 | this.cloneOfBestPlayerFromPreviousGeneration = this.players[this.bestPlayerIndex].clone(); |
| 119 | |
| 120 | nextGen.push(this.players[this.bestPlayerIndex].clone()); |
| 121 | for (let i = 1; i < this.players.length; i++) { |
| 122 | let parent = this.SelectParent(); |
| 123 | let baby = parent.clone() |
| 124 | // if the parent fell to the previous level then mutate the baby at the action that caused them to fall |
| 125 | if(parent.fellToPreviousLevel){ |
| 126 | baby.brain.mutateActionNumber(parent.fellOnActionNo); |
| 127 | } |
| 128 | baby.brain.mutate(); |
| 129 | nextGen.push(baby); |
| 130 | } |
| 131 | |
| 132 | this.players = []; |
| 133 | for (let i = 0; i < nextGen.length; i++) { |
| 134 | this.players[i] = nextGen[i]; |
| 135 | // if(!this.newLevelReached && this.currentBestLevelReached !== 0){// && this.currentBestLevelReached !== 37){ |
| 136 | // this.players[i].loadStartOfBestLevelPlayerState(); |
| 137 | // }<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< |
| 138 | } |
| 139 | |
| 140 | this.gen++; |
| 141 | } |
| 142 | |
| 143 | CalculateFitnessSum() { |
| 144 | this.fitnessSum = 0; |
no test coverage detected