Exemple #1
0
        public void Initialise()
        {
            for (var widthCount = 0; widthCount < width; widthCount++)
            {
                cells[widthCount] = new Cell[height];

                for (var heightCount = 0; heightCount < height; heightCount++)
                {
                    cells[widthCount][heightCount] = new Cell(this, widthCount, heightCount);
                }
            }
        }
Exemple #2
0
        public virtual int NumberOfNeighbours(Cell cell)
        {
            var x = cell.X;
            var y = cell.Y;
            var liveNeighbourCells = 0;

            if (CellIsAlive(x - 1, y - 1)) liveNeighbourCells++; // top left
            if (CellIsAlive(x, y - 1)) liveNeighbourCells++; // top middle
            if (CellIsAlive(x + 1, y - 1)) liveNeighbourCells++; // top right

            if (CellIsAlive(x - 1, y)) liveNeighbourCells++; // middle left
            if (CellIsAlive(x + 1, y)) liveNeighbourCells++; // middle right

            if (CellIsAlive(x - 1, y + 1)) liveNeighbourCells++; // bottom right
            if (CellIsAlive(x, y + 1)) liveNeighbourCells++; // bottom middle
            if (CellIsAlive(x + 1, y + 1)) liveNeighbourCells++; // bottom left

            return liveNeighbourCells;
        }