Example #1
0
 public void InitializeMatrix()
 {
     for (var row = 0; row < RowsNumber; row++)
     {
         for (var column = 0; column < ColumnsNumber; column++)
         {
             _matrix[row, column] = new BioUnit();
         }
     }
 }
Example #2
0
        public void NextRabbitCarrotStep()
        {
            var aux = new BioUnit[RowsNumber, ColumnsNumber];

            for (var row = 0; row < RowsNumber; row++)
            {
                for (var col = 0; col < ColumnsNumber; col++)
                {
                    aux[row, col] = null;

                    var current = _matrix[row, col];

                    if (current != null && current.GetType() == typeof(Carrot))
                    {
                        if (!SurroundingNeighbors(row, col, typeof(Rabbit)).Any())
                        {
                            if (current.WillILive())
                            {
                                aux[row, col] = current;
                            }
                        }
                        else
                        {
                            FirstRabbit(row, col).Eat();
                        }
                    }

                    else if (current != null && current.GetType() == typeof(Rabbit))
                    {
                        if (current.WillILive())
                        {
                            aux[row, col] = current;
                        }
                    }

                    if (SurroundingNeighbors(row, col, typeof(Rabbit)).Count() >= 2)
                    {
                        aux[row, col] = new Rabbit(row, col, this);
                    }
                    else if (SurroundingNeighbors(row, col, typeof(Carrot)).Count() >= 3)
                    {
                        aux[row, col] = new Carrot(row, col, this);
                    }
                }
            }

            for (var row = 0; row < RowsNumber; row++)
            {
                for (var col = 0; col < ColumnsNumber; col++)
                {
                    _matrix[row, col] = aux[row, col];
                }
            }
        }
Example #3
0
 public void Insert(BioUnit unit)
 {
     try
     {
         _matrix[unit.Position.X, unit.Position.Y] = unit;
     }
     catch (Exception)
     {
         // ignored
     }
 }