public void GetLiveCellsThatShouldDieWheTheyHaveLessThanTwoNeighbours()
        {
            var rules   = new DeadEvolutionRules();
            var grid    = new Grid(5, 5);
            var cellOne = new Cell(0, 2);
            var cellTwo = new Cell(0, 1);

            grid.AddCell(cellOne);
            grid.AddCell(cellTwo);

            var neighboursOfAliveCell = new List <IEnumerable <Cell> >
            {
                grid.GetLiveNeighboursOfLivingCell(cellOne),
                grid.GetLiveNeighboursOfLivingCell(cellTwo)
            };

            var expectedDeadCells = new List <Cell> {
                cellOne, cellTwo
            };
            var cellsThatShouldDie =
                rules.GetLiveCellsThatShouldDie(neighboursOfAliveCell, new List <Cell> {
                cellOne, cellTwo
            });

            expectedDeadCells.Should().BeEquivalentTo(cellsThatShouldDie);
            Assert.Equal(2, cellsThatShouldDie.Count);
        }
        public void GetNoLiveCellThatShouldDieWheTheyHaveTwoOrThreeNeighbours()
        {
            var rules     = new DeadEvolutionRules();
            var grid      = new Grid(4, 4);
            var cellOne   = new Cell(0, 0);
            var cellTwo   = new Cell(0, 1);
            var cellThree = new Cell(1, 1);
            var cellFour  = new Cell(1, 2);

            grid.AddCell(cellOne);
            grid.AddCell(cellTwo);
            grid.AddCell(cellThree);
            grid.AddCell(cellFour);

            var neighboursOfAliveCell = new List <IEnumerable <Cell> >
            {
                grid.GetLiveNeighboursOfLivingCell(cellOne),
                grid.GetLiveNeighboursOfLivingCell(cellTwo),
                grid.GetLiveNeighboursOfLivingCell(cellThree),
                grid.GetLiveNeighboursOfLivingCell(cellFour)
            };

            var expectedDeadCells  = new List <Cell>();
            var cellsThatShouldDie = rules.GetLiveCellsThatShouldDie(neighboursOfAliveCell,
                                                                     new List <Cell> {
                cellOne, cellTwo, cellThree, cellFour
            });

            expectedDeadCells.Should().BeEquivalentTo(cellsThatShouldDie);
            Assert.Equal(0, cellsThatShouldDie.Count);
        }
예제 #3
0
        public void GivenADeadCellWithThreeNeighboursThenDeadCellShouldLive()
        {
            var deadEvolutionRules = new DeadEvolutionRules();
            var result             = deadEvolutionRules.CellStateBasedOnNumberOfNeighbours(3);

            Assert.True(result);
        }
        public void GetLiveCellThatShouldDieWhenItHasNoNeighbours()
        {
            var rules    = new DeadEvolutionRules();
            var grid     = new Grid(5, 5);
            var cellFour = new Cell(3, 3);

            grid.AddCell(cellFour);

            var neighboursOfAliveCell = new List <IEnumerable <Cell> >
            {
                grid.GetLiveNeighboursOfLivingCell(cellFour),
            };

            var expectedDeadCells = new List <Cell> {
                cellFour
            };
            var cellsThatShouldDie = rules.GetLiveCellsThatShouldDie(neighboursOfAliveCell, new List <Cell> {
                cellFour
            });

            expectedDeadCells.Should().BeEquivalentTo(cellsThatShouldDie);
            Assert.Equal(1, cellsThatShouldDie.Count);
        }
예제 #5
0
 public GameEngine()
 {
     CurrentWorld        = new GameWorld();
     _liveEvolutionRules = new LiveEvolutionRules();
     _deadEvolutionRules = new DeadEvolutionRules();
 }
예제 #6
0
 public GameOfLife()
 {
     _deadEvolutionRules = new DeadEvolutionRules();
     _liveEvolutionRules = new LiveEvolutionRules();
 }