MCPcopy Create free account
hub / github.com/Code-Bullet/Jump-King / NaturalSelection

Method NaturalSelection

Population.js:113–141  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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;

Callers 2

drawFunction · 0.80
drawFunction · 0.80

Calls 6

SetBestPlayerMethod · 0.95
CalculateFitnessSumMethod · 0.95
SelectParentMethod · 0.95
mutateActionNumberMethod · 0.80
cloneMethod · 0.45
mutateMethod · 0.45

Tested by

no test coverage detected