public void BirthCycle() { List <Herbivore> newbornHerbivores = new List <Herbivore>(); List <Carnivore> newbornCarnivores = new List <Carnivore>(); Herbivores = Herbivores.OrderBy(i => i.Fitness).ToList(); var numHerb = Herbivores.Count(); foreach (var herb in Herbivores) { var result = herb.Birth(numHerb); if (!(result is null)) { newbornHerbivores.Add((Herbivore)result); } } foreach (var child in newbornHerbivores) { Herbivores.Add(child); } NewHerbivores = newbornHerbivores.Count(); TotalHerbivoreLives += newbornHerbivores.Count(); Carnivores = Carnivores.OrderBy(i => i.Fitness).ToList(); var numCarn = Carnivores.Count(); foreach (var carn in Carnivores) { var result = carn.Birth(numCarn); if (!(result is null)) { newbornCarnivores.Add((Carnivore)result); } } foreach (var child in newbornCarnivores) { Carnivores.Add(child); } NewCarnivores = newbornCarnivores.Count(); TotalCarnivoreLives += newbornCarnivores.Count(); }
// Constructor & Overloads public Enviroment(Position pos, Random rng, List <Herbivore> initialHerbivores = null, List <Carnivore> initialCarnivores = null) { Rng = rng; Pos = pos; if (initialHerbivores is null) { Herbivores = new List <Herbivore>(); } else { Herbivores = initialHerbivores; } if (initialCarnivores is null) { Carnivores = new List <Carnivore>(); } else { Carnivores = initialCarnivores; } TotalHerbivoreLives = Herbivores.Count(); TotalCarnivoreLives = Carnivores.Count(); }