Last active
September 9, 2018 01:32
-
-
Save kmaher9/60fe7180631e821bcd3b97d6ec1da289 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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