public void RemoveDeadIndividuals() { DeadCarnivores += Carnivores.Where(i => !i.IsAlive).Count(); DeadHerbivores += Herbivores.Where(i => !i.IsAlive).Count(); List <Herbivore> survivingHerbivores = new List <Herbivore>(); foreach (var herb in Herbivores) { if (herb.IsAlive) { survivingHerbivores.Add(herb); } } List <Carnivore> survivingCarnivores = new List <Carnivore>(); foreach (var carn in Carnivores) { if (carn.IsAlive) { survivingCarnivores.Add(carn); } } Herbivores = survivingHerbivores; Carnivores = survivingCarnivores; }
public void SaveReportData(string filename) { RefreshReportData(); using (var outputFile = new StreamWriter(filename)) { // Data opslaan per regel outputFile.WriteLine(Carnivores.ToString()); // Aantal carnivores outputFile.WriteLine(Herbivores.ToString()); // Aantal herbivores outputFile.WriteLine(Omnivores.ToString()); // Aantal omnivores outputFile.WriteLine(Nonivores.ToString()); // Aantal nonivores // Energie per type outputFile.WriteLine(EnergyCarnivores.ToString()); // carnivores outputFile.WriteLine(EnergyHerbivores.ToString()); // herbivores outputFile.WriteLine(EnergyOmnivores.ToString()); // omnivores outputFile.WriteLine(EnergyNonivores.ToString()); // nonivores // Gemiddeld per type outputFile.WriteLine((EnergyCarnivores / Carnivores).ToString()); // carnivores outputFile.WriteLine((EnergyHerbivores / Herbivores).ToString()); // herbivores outputFile.WriteLine((EnergyOmnivores / Omnivores).ToString()); // omnivores outputFile.WriteLine((EnergyNonivores / Nonivores).ToString()); // nonivores // Aantal planten outputFile.WriteLine(Planten); // Energie planten outputFile.WriteLine(EnergyPlanten.ToString()); // Gemiddeld energie per plant outputFile.WriteLine((EnergyPlanten / Planten).ToString()); } }
public void Apply(CarnivoreDied @event) { var carnivore = Carnivores[@event.CarnivoreId]; Carnivores.Remove(@event.CarnivoreId); Cells[carnivore.X, carnivore.Y] = CellType.Default; }
public int ResetMigrationParameter() { var migrations = Carnivores.Where(i => i.Migrated).Count() + Herbivores.Where(i => i.Migrated).Count(); Carnivores.ForEach(i => i.Migrated = false); Herbivores.ForEach(i => i.Migrated = false); return(migrations); }
public int ResetGivenBirthParameter() { var births = Carnivores.Where(i => i.GivenBirth).Count() + Herbivores.Where(i => i.GivenBirth).Count(); Carnivores.ForEach(i => i.GivenBirth = false); Herbivores.ForEach(i => i.GivenBirth = false); return(births); }
public void CarnivoreFeedingCycle() { Carnivores = Carnivores.OrderBy(i => i.Fitness).ToList(); var kills = 0; foreach (var carn in Carnivores) { kills += carn.Feed(Herbivores); } KilledByCarnivores = kills; RemoveDeadIndividuals(); }
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(); }
public void Apply(CreateCarnivoreAccepted @event) { Cells[@event.X, @event.Y] = CellType.Carnivore; Carnivores.Add(@event.CarnivoreId, new Carnivore(@event.X, @event.Y, @event.CarnivoreId, @event.MovesUntilDeath)); }
public void OverloadAllCarnivores(CarnivoreParams parameters) { // Implement parameter cloning!!! Carnivores.ForEach(i => i.Params = parameters); }
public void WeightLossCycle() { Herbivores.ForEach(i => i.UpdateWeight()); Carnivores.ForEach(i => i.UpdateWeight()); }
public void AgeCycle() { Herbivores.ForEach(i => i.GrowOlder()); Carnivores.ForEach(i => i.GrowOlder()); }
public void DeathCycle() { Carnivores.ForEach(i => i.Death()); Herbivores.ForEach(i => i.Death()); }