public void The_Cell_May_Die_At_Random_If_The_Player_Has_The_Minimum_Number_Of_Live_Cells()
        {
            //--arrange
            var cellGrowthCalculator          = new CellGrowthCalculator();
            var surroundingCellCalculatorMock = new Mock <ISurroundingCellCalculator>().Object;

            var player = new Player("name", new Color(), 1, cellGrowthCalculator, surroundingCellCalculatorMock, true);

            player.LiveCells = CellGrowthCalculator.MinimumLiveCellsForCellDeath;
            var growthScorecard = new GrowthScorecard {
                DeathChanceForStarvedCells = 0
            };

            player.GrowthScorecard = growthScorecard;
            player.GrowthScorecard.HealthyCellDeathChancePercentage = 100;
            var bioCell = new BioCell(player, 1, new Color(), surroundingCellCalculatorMock);

            var surroundingCells = CreateSurroundingCellsWithAllBioCells(player);

            //--act
            var actualResult = cellGrowthCalculator.CalculateCellGrowth(bioCell, player, surroundingCells);

            //--assert
            actualResult.NewDeadCells.ShouldContain(bioCell);
        }
        public void The_Surrounding_Left_Cells_Are_An_EdgeCell_If_At_The_Left_Column_Of_The_Grid()
        {
            //--arrange
            var bioCell = new BioCell(_mockPlayer.Object, 0, Colors.Brown, _surroundingCellCalculator);

            //--act
            var actualSurroundingCells = _surroundingCellCalculator.GetSurroundingCells(bioCell, _dummyDictionary, _dummyDictionary);

            //--assert
            actualSurroundingCells.BottomLeftCell.OutOfGrid.ShouldBe(true);
            actualSurroundingCells.LeftCell.OutOfGrid.ShouldBe(true);
            actualSurroundingCells.TopLeftCell.OutOfGrid.ShouldBe(true);
        }
        public void The_Surrounding_Bottom_Cells_Are_An_EdgeCell_If_At_The_Bottom_Row_Of_The_Grid()
        {
            //--arrange
            var bioCell   = new BioCell(_mockPlayer.Object, _numberOfCells - 1, Colors.Brown, _surroundingCellCalculator);
            var liveCells = new Dictionary <int, BioCell>();

            //--act
            var actualSurroundingCells = _surroundingCellCalculator.GetSurroundingCells(bioCell, liveCells, _dummyDictionary);

            //--assert
            actualSurroundingCells.BottomRightCell.OutOfGrid.ShouldBe(true);
            actualSurroundingCells.BottomCell.OutOfGrid.ShouldBe(true);
            actualSurroundingCells.BottomLeftCell.OutOfGrid.ShouldBe(true);
        }
示例#4
0
        public void It_Checks_For_Cell_Growth_Into_Empty_Cells()
        {
            //--arrange
            _cellGrowthCalculatorMock      = new Mock <ICellGrowthCalculator>();
            _surroundingCellCalculatorMock = new Mock <ISurroundingCellCalculator>();

            var              expectedCellGrowthResult = new CellGrowthResult(new List <BioCell>(), new List <BioCell>());
            BioCell          capturedBioCell          = null;
            Player           capturedPlayer           = null;
            SurroundingCells capturedSurroundingCells = null;

            _cellGrowthCalculatorMock.Setup(mock =>
                                            mock.CalculateCellGrowth(It.IsAny <BioCell>(), It.IsAny <IPlayer>(), It.IsAny <SurroundingCells>()))
            .Returns(expectedCellGrowthResult)
            .Callback <BioCell, Player, SurroundingCells>((w, x, y) =>
            {
                capturedBioCell          = w;
                capturedPlayer           = x;
                capturedSurroundingCells = y;
            });
            _player = new Player("player 1", new Color(), 1,
                                 _cellGrowthCalculatorMock.Object,
                                 _surroundingCellCalculatorMock.Object,
                                 true);

            var cell             = new BioCell(_player, 0, _player.Color, _surroundingCellCalculatorMock.Object);
            var surroundingCells = new SurroundingCells
            {
                TopLeftCell     = GridCell.MakeEmptyCell(0, RelativePosition.TopLeft),
                TopCell         = GridCell.MakeEmptyCell(0, RelativePosition.Top),
                TopRightCell    = GridCell.MakeOutOfGridCell(0, RelativePosition.TopRight),
                RightCell       = GridCell.MakeOutOfGridCell(0, RelativePosition.Right),
                BottomRightCell = GridCell.MakeOutOfGridCell(0, RelativePosition.BottomRight),
                BottomCell      = GridCell.MakeOutOfGridCell(0, RelativePosition.Bottom),
                BottomLeftCell  = GridCell.MakeOutOfGridCell(0, RelativePosition.BottomLeft),
                LeftCell        = GridCell.MakeOutOfGridCell(0, RelativePosition.Left)
            };

            //--act
            var actualCellGrowthResult = _player.CalculateCellGrowth(cell, surroundingCells);

            //--assert
            capturedBioCell.ShouldBeSameAs(cell);
            capturedPlayer.ShouldBeSameAs(_player);
            capturedSurroundingCells.ShouldBeSameAs(surroundingCells);
            actualCellGrowthResult.ShouldBeSameAs(expectedCellGrowthResult);
        }
        public void It_Finds_Live_Cells_To_The_Left()
        {
            //--arrange
            var currentBioCell = new BioCell(_mockPlayer.Object, 1, Colors.Brown, _surroundingCellCalculator);
            var expectedCell   = new BioCell(_mockPlayer.Object, 0, new Color(), _surroundingCellCalculator);
            var liveCells      = new Dictionary <int, BioCell>
            {
                { expectedCell.CellIndex, expectedCell }
            };

            //--act
            var actualSurroundingCells = _surroundingCellCalculator.GetSurroundingCells(currentBioCell, liveCells, _dummyDictionary);

            //--assert
            actualSurroundingCells.LeftCell.ShouldBeSameAs(expectedCell);
            AssertAllEmpty(actualSurroundingCells, leftCellShouldBeEmpty: false);
        }
        public void It_Checks_For_Dead_Cell_Regeneration()
        {
            //--arrange
            var bioCell   = new BioCell(_playerMock.Object, 1, Colors.Brown, _surroundingCellCalculatorMock.Object);
            var liveCells = new Dictionary <int, BioCell>();
            var deadCells = new Dictionary <int, BioCell>();

            var     expectedSurroundingCells = new SurroundingCells();
            BioCell actualBioCellInSurroundingCellCalculation = null;
            Dictionary <int, BioCell> actualLiveCellsInSurroundingCellCalculation = null;
            Dictionary <int, BioCell> actualDeadCellsInSurroundingCellCalculation = null;

            _surroundingCellCalculatorMock
            .Setup(x => x.GetSurroundingCells(It.IsAny <BioCell>(), It.IsAny <Dictionary <int, BioCell> >(), It.IsAny <Dictionary <int, BioCell> >()))
            .Returns(expectedSurroundingCells)
            .Callback <BioCell, Dictionary <int, BioCell>, Dictionary <int, BioCell> >((i, o, x) =>
            {
                actualBioCellInSurroundingCellCalculation   = i;
                actualLiveCellsInSurroundingCellCalculation = o;
                actualDeadCellsInSurroundingCellCalculation = x;
            });

            var              expectedCellGrowthResult = new CellGrowthResult(new List <BioCell>(), new List <BioCell>());
            BioCell          capturedBioCell          = null;
            SurroundingCells capturedSurroundingCells = null;

            _playerMock.Setup(mock => mock.CalculateCellGrowth(It.IsAny <BioCell>(), It.IsAny <SurroundingCells>()))
            .Returns(expectedCellGrowthResult)
            .Callback <BioCell, SurroundingCells>((i, o) =>
            {
                capturedBioCell          = i;
                capturedSurroundingCells = o;
            });

            //--act
            var actualCellGrowthResult = bioCell.RunCellGrowth(liveCells, deadCells);

            //--assert
            actualBioCellInSurroundingCellCalculation.ShouldBeSameAs(bioCell);
            actualLiveCellsInSurroundingCellCalculation.ShouldBeSameAs(liveCells);
            actualDeadCellsInSurroundingCellCalculation.ShouldBeSameAs(deadCells);

            capturedBioCell.ShouldBeSameAs(bioCell);
            capturedSurroundingCells.ShouldBeSameAs(expectedSurroundingCells);
            actualCellGrowthResult.ShouldBeSameAs(expectedCellGrowthResult);
        }
        public void It_Finds_Live_Cells_To_The_Bottom_Left()
        {
            //--arrange
            var secondRowFirstColumnIndex = _numberOfRowsAndColumns;

            var bioCell      = new BioCell(_mockPlayer.Object, 1, Colors.Brown, _surroundingCellCalculator);
            var expectedCell = new BioCell(_mockPlayer.Object, secondRowFirstColumnIndex, new Color(), _surroundingCellCalculator);
            var liveCells    = new Dictionary <int, BioCell>
            {
                { expectedCell.CellIndex, expectedCell }
            };

            //--act
            var actualSurroundingCells = _surroundingCellCalculator.GetSurroundingCells(bioCell, liveCells, new Dictionary <int, BioCell>());

            //--assert
            actualSurroundingCells.BottomLeftCell.ShouldBeSameAs(expectedCell);
            AssertAllEmpty(actualSurroundingCells, bottomLeftCellShouldBeEmpty: false);
        }
        public void It_Gets_New_Live_Cells_Calculated_From_Empty_Ones_Using_The_Players_Growth_Scorecard()
        {
            //--arrange
            var growthScorecard = new GrowthScorecard();

            growthScorecard.GrowthChanceDictionary[RelativePosition.TopLeft] = 100;
            growthScorecard.GrowthChanceDictionary[RelativePosition.Top]     = 100;
            var player = new Player("name", new Color(), 1, _cellGrowthCalculator, _surroundingCellCalculatorMock, true);

            player.GrowthScorecard = growthScorecard;
            var bioCell = new BioCell(player, 1, new Color(), _surroundingCellCalculatorMock);

            var emptyIndex1      = 1;
            var emptyIndex2      = 2;
            var surroundingCells = new SurroundingCells
            {
                //--100% chance
                TopLeftCell = GridCell.MakeEmptyCell(emptyIndex1, RelativePosition.TopLeft),
                //--100% chance
                TopCell         = GridCell.MakeEmptyCell(emptyIndex2, RelativePosition.Top),
                TopRightCell    = GridCell.MakeOutOfGridCell(0, RelativePosition.TopRight),
                RightCell       = GridCell.MakeOutOfGridCell(0, RelativePosition.Right),
                BottomRightCell = GridCell.MakeOutOfGridCell(0, RelativePosition.BottomRight),
                BottomCell      = GridCell.MakeOutOfGridCell(0, RelativePosition.Bottom),
                BottomLeftCell  = GridCell.MakeOutOfGridCell(0, RelativePosition.BottomLeft),
                LeftCell        = GridCell.MakeOutOfGridCell(0, RelativePosition.Left)
            };

            //--act
            var actualResult = _cellGrowthCalculator.CalculateCellGrowth(bioCell, player, surroundingCells);

            //--assert
            actualResult.NewLiveCells.Count.ShouldBe(2);
            actualResult.NewLiveCells.ShouldContain(x => x.CellIndex == emptyIndex1);
            actualResult.NewLiveCells.ShouldContain(x => x.CellIndex == emptyIndex2);
            actualResult.NewDeadCells.ShouldBeEmpty();
        }