示例#1
0
        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;
        }
示例#2
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());
            }
        }
示例#3
0
            public void Apply(CarnivoreDied @event)
            {
                var carnivore = Carnivores[@event.CarnivoreId];

                Carnivores.Remove(@event.CarnivoreId);

                Cells[carnivore.X, carnivore.Y] = CellType.Default;
            }
示例#4
0
        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);
        }
示例#5
0
        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);
        }
示例#6
0
        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();
        }
示例#7
0
        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();
        }
示例#8
0
        // 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();
        }
示例#9
0
 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));
 }
示例#10
0
 public void OverloadAllCarnivores(CarnivoreParams parameters)
 {
     // Implement parameter cloning!!!
     Carnivores.ForEach(i => i.Params = parameters);
 }
示例#11
0
 public void WeightLossCycle()
 {
     Herbivores.ForEach(i => i.UpdateWeight());
     Carnivores.ForEach(i => i.UpdateWeight());
 }
示例#12
0
 public void AgeCycle()
 {
     Herbivores.ForEach(i => i.GrowOlder());
     Carnivores.ForEach(i => i.GrowOlder());
 }
示例#13
0
 public void DeathCycle()
 {
     Carnivores.ForEach(i => i.Death());
     Herbivores.ForEach(i => i.Death());
 }