Skip to content

Instantly share code, notes, and snippets.

@kmaher9
Last active September 9, 2018 01:32
Show Gist options
  • Save kmaher9/60fe7180631e821bcd3b97d6ec1da289 to your computer and use it in GitHub Desktop.
Save kmaher9/60fe7180631e821bcd3b97d6ec1da289 to your computer and use it in GitHub Desktop.
this.selection = function() {
var newSticks = [];
for (var i = 0; i < this.sticks.length; i++) {
var parentA = random(this.pool).dna;
var parentB = random(this.pool).dna;
var child = parentA.crossover(parentB);
//child.mutation();
newSticks[i] = new Stick(child);
}
this.sticks = newSticks;
}
var mid = floor(random(this.genes.length));
for (var i = 0; i < this.genes.length; i++) {
if (i > mid) {
newgenes[i] = this.genes[i];
}
else {
newgenes[i] = partner.genes[i];
}
}
return new dna(newgenes);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment