Esempio n. 1
0
        //generate the next grid depending on the layout of the grid
        public static int[,] GetNextGenGrid(int[,] grid)
        {
            var gridRows = grid.GetUpperBound(0);
            var gridCols = grid.GetUpperBound(1);
            var nextGrid = new int[gridRows + 1, gridCols + 1];

            for (int i = 1; i < gridRows; i++)
            {
                for (int j = 1; j < gridCols; j++)
                {
                    var liveNeighbors = Grid.GetLiveNeighborCell(grid, i, j);

                    if (grid[i, j] == 1)
                    {
                        nextGrid[i, j] = liveNeighbors == 2 || liveNeighbors == 3 ? 1 : 0;
                    }
                    else
                    {
                        nextGrid[i, j] = liveNeighbors == 3 ? 1 : 0;
                    }
                }
            }
            return(nextGrid);
        }