Exemplo n.º 1
0
        public void ReproductionTest()
        {
            #region Arrange

            Cell[,] cells = new Cell[300, 200];
            Cell cell = new Cell()
            {
                IsAlive = false
            };

            _livingNeighborsCounter.Setup(x => x.Count(cells, cell)).Returns(3);

            #endregion

            #region Act

            bool alive = _lifeValidator.IsAlive(cells, cell);

            #endregion

            #region Assert

            Assert.IsTrue(alive, "The cell is dead!");

            #endregion
        }
Exemplo n.º 2
0
        public Cell[,] Run(Cell[,] cells)
        {
            int maxXIndex = cells.GetUpperBound(0);
            int maxYIndex = cells.GetUpperBound(1);

            if (maxXIndex < 2 || maxYIndex < 2)
            {
                throw new ArgumentException("The minimum array size is 3x3.");
            }

            Cell[,] nextGenCells = new Cell[cells.GetLength(0), cells.GetLength(1)];
            Array.Copy(cells, nextGenCells, cells.Length);

            for (int xCoord = 0; xCoord <= maxXIndex; xCoord++)
            {
                for (int yCoord = 0; yCoord <= maxYIndex; yCoord++)
                {
                    bool isAlive = _lifeValidator.IsAlive(cells, cells[xCoord, yCoord]);

                    nextGenCells[xCoord, yCoord].IsAlive = isAlive;
                }
            }

            return(nextGenCells);
        }