public ReadOnlyCell[,] GetCells() { var readOnlyCells = new ReadOnlyCell[_cells.GetLength(0), _cells.GetLength(1)]; for (int x = 0; x < _cells.GetLength(0); x++) { for (int y = 0; y < _cells.GetLength(1); y++) { readOnlyCells[x, y] = _cells[x, y].GetReadOnlyVersion(); } } return(readOnlyCells); }
public CellState GetNextState(ReadOnlyCell currentCell, ReadOnlyCell[] neighbours) { var aliveNeighboursCount = neighbours.Count(n => n.IsAlive()); if (currentCell.IsAlive() && (aliveNeighboursCount < 2 || aliveNeighboursCount > 3)) { return(CellState.Dead); } if (currentCell.IsAlive() && (aliveNeighboursCount == 2 || aliveNeighboursCount == 3)) { return(CellState.Alive); } if (currentCell.IsDead() && aliveNeighboursCount == 3) { return(CellState.Alive); } return(CellState.Dead); }