public Individual crossover2(Individual otherIndividual) { /* * crossover function * clone both parent (the clones will be the new children after the crossover operation) * randomly choose a node from each cloned parent * swap the nodes */ int randNum; const int MIN = 2; // Node objects to temporary hold the returned references Node swap1 = null; Node swap2 = null; // randomize a number ranging from 2....nodesAmount of first parent randNum = rnd.Next(this.getStrategyRoot().countNodes() - MIN + 1) + MIN; // paint the selected nodes at the original first parent this.getStrategyRoot().getNode(this.getStrategyRoot(), randNum).paintNode(Color.Red); // get the first random node reference swap1 = this.getStrategyRoot().getNode(this.getStrategyRoot(), randNum); // randomize a number ranging from 2....nodesAmount of second parent randNum = rnd.Next(otherIndividual.getStrategyRoot().countNodes() - MIN + 1) + MIN; // paint the selected nodes at the original second parent otherIndividual.getStrategyRoot().getNode(otherIndividual.getStrategyRoot(), randNum).paintNode(Color.Red); // get the second random node reference swap2 = otherIndividual.getStrategyRoot().getNode(otherIndividual.getStrategyRoot(), randNum); // paint the swapped nodes swap1.paintNode(Color.Green); swap2.paintNode(Color.Green); // make the reference swaps this.getStrategyRoot().swapNodes(swap1, swap2.copy(swap2)); // combine the parents name to create a new name this.setPlayerName(otherIndividual.getPlayerName()); return(this); }