Beispiel #1
0
 /// <summary>
 /// Generate the future state of the cell based
 /// on the current state as determined by the Life rules.
 /// </summary>
 public void UpdateState()
 {
     for (int i = 0; i < gridHeight; i++)
     {
         for (int j = 0; j < gridWidth; j++)
         {
             var liveNeighbors = GetLiveNeighbors(i, j);
             _nextState[i, j] = LifeRules.GetNewState(CurrentState[i, j], liveNeighbors);
         }
     }
     CurrentState = _nextState;
     _nextState   = new CellState[gridHeight, gridWidth];
 }
Beispiel #2
0
        /// <summary>
        /// Updates state of each cell on the game.
        /// </summary>
        public void UpdateState()
        {
            for (int row = 0; row < GridHeight; row++)
            {
                for (int col = 0; col < GridWidth; col++)
                {
                    var liveNeighbours = GetLiveNeighbours(row, col);
                    nextState[row, col] = LifeRules.GetNewState(CurrentState[row, col], liveNeighbours);
                }
            }

            CurrentState = nextState;
            nextState    = new CellState[GridHeight, GridWidth];
        }
Beispiel #3
0
        public void UpdateState3()
        {
            Parallel.For(0, gridHeight, i =>
            {
                for (int j = 0; j < gridWidth; j++)
                {
                    var liveNeighbors = GetLiveNeighbors(i, j);
                    nextState[i, j]   =
                        LifeRules.GetNewState(CurrentState[i, j], liveNeighbors);
                }
            });

            CurrentState = nextState;
            nextState    = new CellState[gridHeight, gridWidth];
        }