Esempio n. 1
0
        public override void Randomize()
        {
            Random rnd = new Random();

            for (int row = 0; row < _size; row++)
            {
                for (int column = 0; column < _size; column++)
                {
                    //get a random number that is from 0 to 5 inclusive
                    int         random = rnd.Next(6);
                    RedBlueCell cell   = GetCell(row, column);
                    switch (random)
                    {
                    case 0:
                        cell.state = RedBlueState.RED;
                        break;

                    case 1:
                        cell.state = RedBlueState.BLUE;
                        break;

                    default:
                        cell.state = RedBlueState.DEAD;
                        break;
                    }
                }
            }
        }
Esempio n. 2
0
 public RedBlueLife(int inSize)
 {
     this._size = inSize;
     cells = new RedBlueCell[_size,_size];
     for (int row =0; row < _size; row++)
     {
         for (int column = 0; column < _size; column++)
         {
             cells[row, column] = new RedBlueCell();
         }
     }
 }
Esempio n. 3
0
 public RedBlueLife(int inSize)
 {
     this._size = inSize;
     cells      = new RedBlueCell[_size, _size];
     for (int row = 0; row < _size; row++)
     {
         for (int column = 0; column < _size; column++)
         {
             cells[row, column] = new RedBlueCell();
         }
     }
 }
Esempio n. 4
0
 private bool isAlive(int row, int column)
 {
     if (row < 0 || row >= _size || column < 0 || column >= _size)
     {
         return(false);
     }
     else
     {
         RedBlueCell cell = GetCell(row, column);
         return(cell.state == RedBlueState.RED || cell.state == RedBlueState.BLUE);
     }
 }
Esempio n. 5
0
        public override void Iterate()
        {
            RedBlueCell[,] newCells = new RedBlueCell[_size,_size];

            for (int row = 0; row < _size; row++)
            {
                for (int column = 0; column < _size; column++)
                {
                    int living = countLivingSurroundingCells(row, column);
                    RedBlueState victoriousState = getVictors(row, column); //this species wins in this area
                    if (isAlive(row, column)) {
                        if (living == 2 || living == 3)
                        {
                            RedBlueState dominantSpecies = getVictors(row, column);
                            newCells[row, column] = new RedBlueCell(dominantSpecies);
                            
                        }
                        else
                        {
                            newCells[row,column] = new RedBlueCell(RedBlueState.DEAD); //dead
                        }
                    }
                    else
                    {
                        if (living == 3)
                        {
                            RedBlueState dominantSpecies = getVictors(row, column);
                            newCells[row, column] = new RedBlueCell(dominantSpecies); //no tie possible here
                        }
                        else
                        {
                            newCells[row, column] = new RedBlueCell(RedBlueState.DEAD);
                        }
                    }
                }
            }
            cells = newCells;
                    
        }
Esempio n. 6
0
        public override void Iterate()
        {
            RedBlueCell[,] newCells = new RedBlueCell[_size, _size];

            for (int row = 0; row < _size; row++)
            {
                for (int column = 0; column < _size; column++)
                {
                    int          living          = countLivingSurroundingCells(row, column);
                    RedBlueState victoriousState = getVictors(row, column); //this species wins in this area
                    if (isAlive(row, column))
                    {
                        if (living == 2 || living == 3)
                        {
                            RedBlueState dominantSpecies = getVictors(row, column);
                            newCells[row, column] = new RedBlueCell(dominantSpecies);
                        }
                        else
                        {
                            newCells[row, column] = new RedBlueCell(RedBlueState.DEAD); //dead
                        }
                    }
                    else
                    {
                        if (living == 3)
                        {
                            RedBlueState dominantSpecies = getVictors(row, column);
                            newCells[row, column] = new RedBlueCell(dominantSpecies); //no tie possible here
                        }
                        else
                        {
                            newCells[row, column] = new RedBlueCell(RedBlueState.DEAD);
                        }
                    }
                }
            }
            cells = newCells;
        }