static void Evolve() { //natural selection Specie.Niche(); SortMembers(); int mid = members.Count / 2; int deadCount = 0; for (int i = members.Count - 1; i >= mid; i--) { deadCount++; DNA dna = members[i]; members.Remove(dna); dna.specie.RemoveMember(dna); } //repopulation int mothercount = members.Count; for (int i = 0; i < deadCount; i++) { int index = i % mothercount; DNA father = members[index]; int fatherIndex = father.specie.members.IndexOf(father); int motherIndex = (fatherIndex + 1) % father.specie.members.Count; DNA mother = father.specie.members[motherIndex]; DNA baby = father.Mate(mother); members.Add(baby); } Saver.BinarySave(_path + "species", Specie.species); Saver.BinarySave(_path + "dnaData", members); CreateAgents(); onEvolve?.Invoke(); }