Esempio n. 1
0
        // evolve life
        public void Evolve()
        {
            // copy space for testing (not modified) cells
            bool[,] copySpace = new bool[HEIGHT, WIDTH];
            for (int r = 0; r < HEIGHT; r++)
            {
                for (int c = 0; c < WIDTH; c++)
                {
                    copySpace[r, c] = this.space[r, c];
                }
            }

            // process each row
            for (int r = 0; r < HEIGHT; r++)
            {
                // process each column
                for (int c = 0; c < WIDTH; c++)
                {
                    // current cell live of dead? (use copy space!)
                    bool livingCell = copySpace[r, c];

                    // get number of live (surrounding) cells
                    int neighBourCount = GetLiveNeighbours(copySpace, r, c);

                    // cell should live?
                    this.space[r, c] = lifeBehaviour.CellShouldLive(livingCell, neighBourCount);
                }
            }
        }
Esempio n. 2
0
 private bool CellShouldLive(bool cell, int neighboursCount) => lifeBehaviour.CellShouldLive(cell, neighboursCount);