private void AssertAllEmpty(SurroundingCells surroundingCells,
                                    bool topLeftCellShouldBeEmpty     = true,
                                    bool leftCellShouldBeEmpty        = true,
                                    bool topCellShouldBeEmpty         = true,
                                    bool topRightCellShouldBeEmpty    = true,
                                    bool rightCellShouldBeEmpty       = true,
                                    bool bottomRightCellShouldBeEmpty = true,
                                    bool bottomCellShouldBeEmpty      = true,
                                    bool bottomLeftCellShouldBeEmpty  = true)
        {
            if (leftCellShouldBeEmpty)
            {
                surroundingCells.LeftCell.OrganicCell.ShouldBeFalse();
            }

            if (topLeftCellShouldBeEmpty)
            {
                surroundingCells.TopLeftCell.OrganicCell.ShouldBeFalse();
            }

            if (topCellShouldBeEmpty)
            {
                surroundingCells.TopCell.OrganicCell.ShouldBeFalse();
            }

            if (topRightCellShouldBeEmpty)
            {
                surroundingCells.TopRightCell.OrganicCell.ShouldBeFalse();
            }

            if (rightCellShouldBeEmpty)
            {
                surroundingCells.RightCell.OrganicCell.ShouldBeFalse();
            }

            if (bottomRightCellShouldBeEmpty)
            {
                surroundingCells.BottomRightCell.OrganicCell.ShouldBeFalse();
            }

            if (bottomCellShouldBeEmpty)
            {
                surroundingCells.BottomCell.OrganicCell.ShouldBeFalse();
            }

            if (bottomLeftCellShouldBeEmpty)
            {
                surroundingCells.BottomLeftCell.OrganicCell.ShouldBeFalse();
            }
        }
        private SurroundingCells CreateSurroundingCellsWithAllBioCells(Player player)
        {
            var surroundingCells = new SurroundingCells
            {
                TopLeftCell     = CreateBioCell(player, 2, _surroundingCellCalculatorMock),
                TopCell         = CreateBioCell(player, 3, _surroundingCellCalculatorMock),
                TopRightCell    = CreateBioCell(player, 4, _surroundingCellCalculatorMock),
                RightCell       = CreateBioCell(player, 5, _surroundingCellCalculatorMock),
                BottomRightCell = CreateBioCell(player, 6, _surroundingCellCalculatorMock),
                BottomCell      = CreateBioCell(player, 7, _surroundingCellCalculatorMock),
                BottomLeftCell  = CreateBioCell(player, 8, _surroundingCellCalculatorMock),
                LeftCell        = CreateBioCell(player, 9, _surroundingCellCalculatorMock)
            };

            return(surroundingCells);
        }
Пример #3
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);
        }
Пример #4
0
        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_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();
        }