public IEvolvableSkull MakeChild(IEvolvableSkull mate) { int g; // Create a new random child var child = new EvolvableSkullViewModel(this.Parent, Guid.NewGuid()); // Set the genes to be a combination of each of the 2 parents. // We'll do this by using crossover and then adding mutations. // Find crossover point var crossoverPoint = (int)(RAND.NextDouble() * this.GenotypeLength); // The first genes are from this parent. for (g = 0; g < crossoverPoint; g++) { child.GenotypeColours[g] = this.GenotypeColours[g]; child.GenotypeWidths[g] = this.GenotypeWidths[g]; child.GenotypeHeights[g] = this.GenotypeHeights[g]; } // The rest of the genes are from the mate. for (g = crossoverPoint; g < GenotypeLength; g++) { child.GenotypeColours[g] = mate.GenotypeColours[g]; child.GenotypeWidths[g] = mate.GenotypeWidths[g]; child.GenotypeHeights[g] = mate.GenotypeHeights[g]; } child.CreateGeneSequence(new RandomInitialGeneSequence(), false); // return the new Crossover, Mutated child organism return(child); }
public IEvolvableSkull Clone() { var theClone = new EvolvableSkullViewModel(this.Parent, Guid.NewGuid()); theClone.GenotypeLength = this.GenotypeLength; theClone.GenotypeMutationRate = this.GenotypeMutationRate; for (int i = 0; i < this.GenotypeColours.Length; i++) { theClone.GenotypeColours[i] = this.GenotypeColours[i]; } for (int i = 0; i < this.GenotypeWidths.Length; i++) { theClone.GenotypeWidths[i] = this.GenotypeWidths[i]; } for (int i = 0; i < this.GenotypeHeights.Length; i++) { theClone.GenotypeHeights[i] = this.GenotypeHeights[i]; } for (int i = 0; i < this.AvailableColours.Length; i++) { theClone.AvailableColours[i] = this.AvailableColours[i]; } for (int i = 0; i < this.AvailableEyeColours.Length; i++) { theClone.AvailableEyeColours[i] = this.AvailableEyeColours[i]; } return(theClone); }