示例#1
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();
        }
示例#2
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));
 }