public static IEnumerator SolveCannon() { pop = new Population(10, 5); yield return(CalcFitness()); while (pop.generation < pop.genLimit) { foreach (Gene g in pop.individuals) { Debug.Log("p " + g.power + " a " + g.angle + " f " + g.fitness); } Gene g1 = pop.individuals[0]; Gene g2 = pop.individuals[1]; if (pop.individuals[0].fitness < 9) { Gene g = pop.individuals[0]; CannonMaster.CurrentCannon.SetAim(g.angle, g.power); Debug.Log("Winner " + g.power + " " + g.angle); break; } System.Random r = new System.Random((int)Time.time); if (r.Next(1, 101) <= pop.crossbreed) { Gene.Crossbreed(ref g1, ref g2); pop.individuals.RemoveAt(pop.individuals.Count - 1); pop.individuals.RemoveAt(pop.individuals.Count - 1); pop.individuals.Add(g1); pop.individuals.Add(g2); } foreach (Gene g in pop.individuals) { System.Random rand = new System.Random((int)Time.time); if (rand.Next(1, 101) <= pop.mutate) { Gene.Mutate(g, r.Next(70, 101), true); } if (r.Next(1, 101) <= pop.mutate) { Gene.Mutate(g, r.Next(40, 91), false); } } pop.generation++; Debug.Log(pop.generation); yield return(CalcFitness()); } }