public Pic BreedWith(Pic partner, Random r, GameState state) { var result = Clone(state); var partnerClone = partner.Clone(state); if (result.type != partner.type && r.Next(0, Settings.CROSSOVER_ROOT_CHANCE) == 0) { //Not gradient -> gradient if (partner.type == PicType.GRADIENT) { result.pos = new float[partner.pos.Length]; Array.Copy(partner.pos, result.pos, partner.pos.Length); result.colors = new Color[partner.colors.Length]; Array.Copy(partner.colors, result.colors, partner.colors.Length); var newMachines = new StackMachine[1]; var newTrees = new AptNode[1]; var(tree, machine) = result.GetRandomTree(r); newTrees[0] = tree.Clone(); newMachines[0] = new StackMachine(newTrees[0]); result.Machines = newMachines; result.Trees = newTrees; } //Gradient -> not gradient else if (result.type == PicType.GRADIENT) { result.pos = null; result.colors = null; var newMachines = new StackMachine[3]; var newTrees = new AptNode[3]; var i = r.Next(0, newTrees.Length); newTrees[i] = result.Trees[0].Clone(); newMachines[i] = new StackMachine(newTrees[i]); for (i = 0; i < newTrees.Length; i++) { if (newTrees[i] == null) { newTrees[i] = AptNode.GetRandomLeaf(r, video); newMachines[i] = new StackMachine(newTrees[i]); } } result.Trees = newTrees; result.Machines = newMachines; } result.type = partner.type; return(result); } else { var(ft, fs) = result.GetRandomTree(r); var(st, ss) = partnerClone.GetRandomTree(r); var rootBred = ft.BreedWith(st, r, video); if (rootBred != null) { for (int i = 0; i < result.Trees.Length; i++) { if (result.Trees[i] == ft) { result.Trees[i] = rootBred; } } } return(result); } }