| 3 | |
| 4 | |
| 5 | class Population { |
| 6 | |
| 7 | constructor(size) { |
| 8 | this.popSize = size; |
| 9 | this.players = []; |
| 10 | for (let i = 0; i < size; i++) { |
| 11 | this.players.push(new Player()); |
| 12 | } |
| 13 | |
| 14 | this.showingFail = false; |
| 15 | this.failPlayerNo = 0; |
| 16 | this.bestPlayerIndex = 0; |
| 17 | this.currentHighestPlayerIndex = 0; |
| 18 | this.fitnessSum = 0; |
| 19 | this.gen = 1; |
| 20 | this.bestHeight = 0; |
| 21 | this.showingLevelNo = 0; |
| 22 | this.currentBestLevelReached = 0; |
| 23 | this.purgeTheSlackers = false; |
| 24 | this.reachedBestLevelAtActionNo = 0; |
| 25 | this.newLevelReached = false; |
| 26 | this.cloneOfBestPlayerFromPreviousGeneration = this.players[0].clone(); |
| 27 | } |
| 28 | |
| 29 | Update() { |
| 30 | for (let i = 0; i < this.players.length; i++) { |
| 31 | this.players[i].Update(); |
| 32 | // if(this.players[i].currentLevelNo >0 && !this.showingFail ){ |
| 33 | // this.showingFail= true; |
| 34 | // this.failPlayerNo = i; |
| 35 | // this.ResetAllPlayers() |
| 36 | // } |
| 37 | } |
| 38 | |
| 39 | } |
| 40 | |
| 41 | SetBestPlayer() { |
| 42 | |
| 43 | this.bestPlayerIndex = 0; |
| 44 | this.newLevelReached = false; |
| 45 | for (let i = 0; i < this.players.length; i++) { |
| 46 | if (this.players[i].bestHeightReached > this.players[this.bestPlayerIndex].bestHeightReached) { |
| 47 | this.bestPlayerIndex = i; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | if (this.players[this.bestPlayerIndex].bestLevelReached > this.currentBestLevelReached) { |
| 52 | this.currentBestLevelReached = this.players[this.bestPlayerIndex].bestLevelReached; |
| 53 | this.newLevelReached = true; |
| 54 | this.reachedBestLevelAtActionNo = this.players[this.bestPlayerIndex].bestLevelReachedOnActionNo; |
| 55 | print("NEW LEVEL, action number", this.reachedBestLevelAtActionNo) |
| 56 | } |
| 57 | this.bestHeight = this.players[this.bestPlayerIndex].bestHeightReached; |
| 58 | } |
| 59 | |
| 60 | SetCurrentHighestPlayer() { |
| 61 | this.currentHighestPlayerIndex = 0; |
| 62 | for (let i = 0; i < this.players.length; i++) { |
nothing calls this directly
no outgoing calls
no test coverage detected