private void Display(ICoop coop) { var animals = coop.GetAllAnimals(); string log; List <string> animalTypes = animals.Select(x => x.Name).Distinct().ToList(); foreach (var animalType in animalTypes) { int maleCount = animals.Count(x => x.Name == animalType && x.Gender == Gender.Male);; int femaleCount = animals.Count(x => x.Name == animalType && x.Gender == Gender.Female); log = $"Name: {animalType}, Male: {maleCount}, Female:{femaleCount}"; Logger.Log(log); } int totalCycle = animals.Max(x => x.BirthCycle); log = $"Total Cycle: {totalCycle}"; Logger.Log(log); Logger.Log("-------------------------------------------"); foreach (var animal in animals) { log = $"Cycle: {animal.BirthCycle} Name: {animal.Name}, Gender: {animal.Gender}, Age: {animal.Age}"; Logger.Log(log); } Logger.Log("Simulation Finished"); }
public SimulatePopulation() { var config = AppConfiguration.GetConfig(); _coop = PopulationState.GetInitialCoopState(config); _simulationCycle = config.CyclePeriodAtMonth; }
private void GiveBirthAnimal(ICoop coop, int cycle) { var newBirthAnimals = new List <IAnimal>(); for (int i = 0; i < coop.GetAllAnimals().Count; i++) { IAnimal animal = coop.GetAnimal(i); animal.Age++; if (CanGiveBirth(animal)) { var newBirth = CreateNewBirths((FemaleAnimal)animal, cycle); newBirthAnimals.AddRange(newBirth); } } coop.AddRangeAnimal(newBirthAnimals); }
public SimulatePopulation(ICoop coop, int simulationCycle) { _coop = coop; _simulationCycle = simulationCycle; }