public double[] GeneticMaximum() { GeneticBrain thisBrain = new GeneticBrain(); const int numWalkers = 500; double[] final = new double[2]; Random rnd = new Random(); int stepIndex = new int(); // Define a number of walkers on the field to be bred. GeneticWalker[] walkers = new GeneticWalker[numWalkers]; // Initialize the walkers. for (int i = 0; i < numWalkers; i++) walkers[i] = new GeneticWalker(); for (int walkerIndex = 0; walkerIndex < numWalkers; walkerIndex++) { for (stepIndex = 0; stepIndex < walkers[walkerIndex].walkerHistory.Length; stepIndex++) { int step = rnd.Next(0, 3) - 1; if (rnd.Next(0, 2) == 1) { walkers[walkerIndex].walkerPosition[0] += step * walkers[walkerIndex].dx; walkers[walkerIndex].walkerHistory[stepIndex] = new Complex(step * walkers[walkerIndex].dx, 0); } else { walkers[walkerIndex].walkerPosition[1] += step * walkers[walkerIndex].dx; walkers[walkerIndex].walkerHistory[stepIndex] = new Complex(0, step * walkers[walkerIndex].dx); } } walkers[walkerIndex].height = walkers[walkerIndex].walkerHeight(); } thisBrain.SortWalkers(ref walkers); for (int i = 0; i < 1500; i++ ) { GeneticWalker[] temp = walkers; thisBrain.SortWalkers(ref temp); thisBrain.BreedWalkers(ref walkers); thisBrain.WalkFromHistory(ref walkers); thisBrain.SortWalkers(ref walkers); if (temp[0].height > walkers[0].height) walkers = temp; Console.WriteLine(Convert.ToString(i)+": "+Convert.ToString(Math.Sqrt(Math.Pow(walkers[0].walkerPosition[0]-3.4,2)+Math.Pow(walkers[0].walkerPosition[1]+4,2)))); } thisBrain.SortWalkers(ref walkers); final = walkers[0].walkerPosition; return final; }