Esempio n. 1
0
        void eval()
        {
            List <Cell> cells    = grid.GetCells();
            List <Cell> toChange = new List <Cell>();

            foreach (Cell c in cells)
            {
                int n = grid.GetNeighbors(c);

                if (grid.IsAlive(c))
                {
                    if (n < 2 || n > 3)
                    {
                        toChange.Add(c);
                    }
                }
                else
                {
                    if (n == 3)
                    {
                        toChange.Add(c);
                    }
                }
            }

            grid.Change(toChange);
        }
Esempio n. 2
0
        public void AnyDeadCellWithExactlyThreeLiveNeighboursBecomesALiveCellAsIfByReproduction()
        {
            var grid = new Grid(new Cell(0, 0), new Cell(1, 0), new Cell(2, 0));

            grid = grid.CreateNextGeneration();

            Assert.True(grid.IsAlive(new Cell(1, 1)));
        }
Esempio n. 3
0
        public void AnyLiveCellWithTwoLiveNeighboursLivesOnToTheNextGeneration()
        {
            var grid = new Grid(new Cell(1, 1), new Cell(0, 1), new Cell(2, 1));

            grid.CreateNextGeneration();

            Assert.True(grid.IsAlive(new Cell(1, 1)));
        }
Esempio n. 4
0
        public void AnyLiveCellWithMoreThanThreeLiveNeighboursDiesAsIfByOvercrowding()
        {
            var grid = new Grid(new Cell(0, 0), new Cell(1, 0), new Cell(2, 0), new Cell(0, 1), new Cell(1, 1));

            grid = grid.CreateNextGeneration();

            Assert.False(grid.IsAlive(new Cell(1, 1)));
        }
Esempio n. 5
0
        public void AnyLiveCellWithFewerThanTwoLiveNeighboursDiesAsIfCausedByUnderPopulation()
        {
            var grid = new Grid(new Cell(1, 1), new Cell(0, 1));

            grid = grid.CreateNextGeneration();

            Assert.False(grid.IsAlive(new Cell(1, 1)));
        }