else {
best = NEATParent.Dad;
}
}
final Chromosome babyNeurons = new Chromosome();
final Chromosome babyGenes = new Chromosome();
final List<Long> vecNeurons = new ArrayList<Long>();
int curMom = 0;
int curDad = 0;
NEATLinkGene momGene;
NEATLinkGene dadGene;
NEATLinkGene selectedGene = null;
while ((curMom < mom.getNumGenes()) || (curDad < dad.getNumGenes())) {
if (curMom < mom.getNumGenes()) {
momGene = (NEATLinkGene) mom.getLinks().get(curMom);
} else {
momGene = null;
}
if (curDad < dad.getNumGenes()) {
dadGene = (NEATLinkGene) dad.getLinks().get(curDad);
} else {
dadGene = null;
}
if ((momGene == null) && (dadGene != null)) {
if (best == NEATParent.Dad) {
selectedGene = dadGene;
}
curDad++;
} else if ((dadGene == null) && (momGene != null)) {
if (best == NEATParent.Mom) {
selectedGene = momGene;
}
curMom++;
} else if (momGene.getInnovationId() < dadGene.getInnovationId()) {
if (best == NEATParent.Mom) {
selectedGene = momGene;
}
curMom++;
} else if (dadGene.getInnovationId() < momGene.getInnovationId()) {
if (best == NEATParent.Dad) {
selectedGene = dadGene;
}
curDad++;
} else if (dadGene.getInnovationId() == momGene.getInnovationId()) {
if (Math.random() < 0.5f) {
selectedGene = momGene;
}
else {
selectedGene = dadGene;
}
curMom++;
curDad++;
}
if (babyGenes.size() == 0) {
babyGenes.add(selectedGene);
}
else {
if (((NEATLinkGene) babyGenes.get(babyGenes.size() - 1))
.getInnovationId() != selectedGene.getInnovationId()) {
babyGenes.add(selectedGene);
}
}
// Check if we already have the nodes referred to in SelectedGene.
// If not, they need to be added.