コード例 #1
0
        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());
            }
        }
コード例 #2
0
ファイル: Enviroment.cs プロジェクト: Wisetorsk/BioSimCSharp
        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;
        }
コード例 #3
0
 /// <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);
     }
 }
コード例 #4
0
ファイル: Zoo.cs プロジェクト: hebgehogg/Zoo
        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");
        }
コード例 #5
0
ファイル: Enviroment.cs プロジェクト: Wisetorsk/BioSimCSharp
        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);
        }
コード例 #6
0
ファイル: Enviroment.cs プロジェクト: Wisetorsk/BioSimCSharp
        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);
        }
コード例 #7
0
ファイル: Enviroment.cs プロジェクト: Wisetorsk/BioSimCSharp
 public void HerbivoreFeedingCycle()
 {
     Herbivores = Herbivores.OrderBy(i => i.Fitness).ToList();
     foreach (var herb in Herbivores)
     {
         Food = herb.Feed(Food);
     }
 }
コード例 #8
0
ファイル: Continent.cs プロジェクト: Kostyachzhan/Homework
        public void deleteHerbivore()
        {
            var toDelete = Herbivores.Where(h => h.HitPoints <= 0).ToList();

            foreach (var td in toDelete)
            {
                Herbivores.Remove(td);
            }
        }
コード例 #9
0
ファイル: Continent.cs プロジェクト: Kostyachzhan/Homework
        public void reproduceHerbivore()
        {
            var toRepoduce = Herbivores.Where(h => h.HitPoints > 150 && h.Satiety > 150).ToList();

            foreach (var tr in toRepoduce)
            {
                Herbivores.Add(tr);
            }
        }
コード例 #10
0
            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;
            }
コード例 #11
0
        /// <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);
            }
        }
コード例 #12
0
ファイル: Enviroment.cs プロジェクト: Wisetorsk/BioSimCSharp
        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();
        }
コード例 #13
0
ファイル: Enviroment.cs プロジェクト: Wisetorsk/BioSimCSharp
        // 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();
        }
コード例 #14
0
ファイル: Enviroment.cs プロジェクト: Wisetorsk/BioSimCSharp
 public void OverloadAllHerbivores(HerbivoreParams parameters)
 {
     // Implement parameter cloning!!!
     Herbivores.ForEach(i => i.Params = parameters);
 }
コード例 #15
0
 public void Apply(CreateHerbivoreAccepted @event)
 {
     Cells[@event.X, @event.Y] = CellType.Herbivore;
     Herbivores.Add(@event.HerbivoreId, new Herbivore(@event.X, @event.Y, @event.HerbivoreId));
 }
コード例 #16
0
ファイル: Enviroment.cs プロジェクト: Wisetorsk/BioSimCSharp
 public void DeathCycle()
 {
     Carnivores.ForEach(i => i.Death());
     Herbivores.ForEach(i => i.Death());
 }
コード例 #17
0
ファイル: Enviroment.cs プロジェクト: Wisetorsk/BioSimCSharp
 public void AgeCycle()
 {
     Herbivores.ForEach(i => i.GrowOlder());
     Carnivores.ForEach(i => i.GrowOlder());
 }
コード例 #18
0
ファイル: Enviroment.cs プロジェクト: Wisetorsk/BioSimCSharp
 public void WeightLossCycle()
 {
     Herbivores.ForEach(i => i.UpdateWeight());
     Carnivores.ForEach(i => i.UpdateWeight());
 }