/// <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]; }
/// <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]; }
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]; }