Patru put you on the right track. It's a handful of issues resolved here: https://gist.github.com/matt-glover/9700810
The original code does not use NUM_OFFSPRING
. Even if it did it also pulls 10 animals back as alphas (or tries to anyway) so NUM_OFFSPRING
really should be bigger to see the alpha selection show any impact.
The original code sorts the animals in place to find alphas but does not actually keep the top 10. Instead it returns the top 10 from the method call but stores the full sorted @animals
array.
Mating needs to produce a new Animal
otherwise the same animal can be selected over and over again in the mating stage. The original code keeps the results only from the last mating attempt stored in the first animal in the mating pair. This eventually eliminates the animal pool to a single animal showing up multiple times in the animals list and only reflecting the genes from the last mating attempt that iteration.
Finally the include_spartans?
check either needs to map the genes as done in the example or call through to each animal and perform the check there. The old code was checking an animal instance against an array of ones.