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 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; }
/// <summary> /// Add new Herbivore to Herbivores array. /// </summary> /// <param name="animal"> Herbivore animal. </param> public void AddHerbivores(Herbivores animal) { if (_hebrivores.Count <= _maximumNumberOfHebrivores) { _hebrivores.Add(animal); } }
private void Animal_DeadEvent(object sender, System.EventArgs e) { var animal = (Animal)sender; animal.DeadEvent -= Animal_DeadEvent; if (animal is Predator predator) { Logger.Info($"The {animal.Name} died"); Predators.Remove(predator); if (animal is Lion lion) { Predators.Add(AnimalFactory.GetAnimal <Lion>()); } if (animal is Fox fox) { Predators.Add(AnimalFactory.GetAnimal <Fox>()); } } if (animal is Herbivore herbivore) { Logger.Info($"The {animal.Name} died"); Herbivores.Remove(herbivore); if (animal is Goat goat) { Herbivores.Add(AnimalFactory.GetAnimal <Goat>()); } if (animal is Ram ram) { Herbivores.Add(AnimalFactory.GetAnimal <Ram>()); } } Logger.Info("The " + animal.Name + " born"); }
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 HerbivoreFeedingCycle() { Herbivores = Herbivores.OrderBy(i => i.Fitness).ToList(); foreach (var herb in Herbivores) { Food = herb.Feed(Food); } }
public void deleteHerbivore() { var toDelete = Herbivores.Where(h => h.HitPoints <= 0).ToList(); foreach (var td in toDelete) { Herbivores.Remove(td); } }
public void reproduceHerbivore() { var toRepoduce = Herbivores.Where(h => h.HitPoints > 150 && h.Satiety > 150).ToList(); foreach (var tr in toRepoduce) { Herbivores.Add(tr); } }
public void Apply(CarnivoreAteHerbivore @event) { var carnivore = Carnivores[@event.CarnivoreId]; var herbivore = Herbivores.Values.Single(h => h.X == @event.NewPosition.X && h.Y == @event.NewPosition.Y); Cells[carnivore.X, carnivore.Y] = CellType.Default; carnivore.Eat(herbivore); Herbivores.Remove(herbivore.Id); Cells[herbivore.X, herbivore.Y] = CellType.Carnivore; }
/// <summary> /// Method creates a new animal by type and adds it to List. /// </summary> /// <param name="animalType"> Animal type. </param> /// <param name="numberOfRows"> Playgrounds number of rows. </param> /// <param name="numberOfColumns"> Playgrounds number of columns. </param> private void AddAnumalToList(Type animalType, int numberOfRows, int numberOfColumns) { object instanceOfAnimal = Activator.CreateInstance(animalType, numberOfRows, numberOfColumns); if (animalType.BaseType.Name.ToString() == "Hunters") { Hunters hunters = (Hunters)instanceOfAnimal; AddHunters(hunters); } else { Herbivores herbivores = (Herbivores)instanceOfAnimal; AddHerbivores(herbivores); } }
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 OverloadAllHerbivores(HerbivoreParams parameters) { // Implement parameter cloning!!! Herbivores.ForEach(i => i.Params = parameters); }
public void Apply(CreateHerbivoreAccepted @event) { Cells[@event.X, @event.Y] = CellType.Herbivore; Herbivores.Add(@event.HerbivoreId, new Herbivore(@event.X, @event.Y, @event.HerbivoreId)); }
public void DeathCycle() { Carnivores.ForEach(i => i.Death()); Herbivores.ForEach(i => i.Death()); }
public void AgeCycle() { Herbivores.ForEach(i => i.GrowOlder()); Carnivores.ForEach(i => i.GrowOlder()); }
public void WeightLossCycle() { Herbivores.ForEach(i => i.UpdateWeight()); Carnivores.ForEach(i => i.UpdateWeight()); }