Exemplo n.º 1
0
        public void ValidateDrawDirectionShape(BattleShip.Direction shipDirection, bool[,] expectedShape)
        {
            RandomMock _random = new RandomMock((int)shipDirection);

            BattleShip _battleShip = new BattleShip(_random);

            Assert.Equal(_battleShip.GetShape(), expectedShape);
        }
Exemplo n.º 2
0
        public void MakeMoveShouldMakeWinningMoveForX()
        {
            //arrange
            GameMock
            .Setup(a => a.GameIsOver)
            .Returns(false);

            GameMock
            .Setup(a => a.GameBoardString)
            .Returns(AGameBoardString);

            GameMock
            .Setup(a => a.CurrentPlayer)
            .Returns(Player.X);

            var moveResponses = new MoveResponse[]
            {
                new MoveResponse()
                {
                    Response = Move.Northern,
                    Outcome  = GameState.XWin,
                    Board    = "_________",
                    Player   = Player.X
                },
                new MoveResponse()
                {
                    Response = Move.Center,
                    Outcome  = GameState.OWin,
                    Board    = "_________",
                    Player   = Player.X
                },
                new MoveResponse()
                {
                    Response = Move.Southern,
                    Outcome  = GameState.Tie,
                    Board    = "_________",
                    Player   = Player.X
                }
            };

            MoveDataAccessMock
            .Setup(a => a.FindMoveResponses(AGameBoardString, Player.X))
            .Returns(moveResponses);

            RandomMock
            .Setup(a => a.Next(It.IsAny <int>()))
            .Returns(0);

            //act
            OmniscientGod.MakeMove(GameMock.Object);

            //assert
            GameMock
            .Verify(a => a.Move(Move.Northern), Times.Once());
        }
Exemplo n.º 3
0
        public void ValidateEndCoordinates(BattleShip.Direction shipDirection, Coordinate endCoordinate, int boardWidth, int boardHeight)
        {
            RandomMock _randomMock = new RandomMock((int)shipDirection);

            BattleShip _battleShip = new BattleShip(_randomMock);

            _randomMock = new RandomMock(0);

            _battleShip.PickRandomPosition(boardWidth, boardHeight, _randomMock);

            Assert.True(_battleShip.GetEndCoordinates().X == endCoordinate.X && _battleShip.GetEndCoordinates().Y == endCoordinate.Y);
        }
Exemplo n.º 4
0
        public void TestShapeDoesNotFitOnBoard()
        {
            RandomMock _randomMock = new RandomMock((int)BattleShip.Direction.North);

            BattleShip _battleShip = new BattleShip(_randomMock);

            _randomMock = new RandomMock(new List <int> {
                10, 10, 5, 5
            });

            _battleShip.PickRandomPosition(10, 10, _randomMock);

            Assert.True(_battleShip.GetStartCoordinates().X == 5 && _battleShip.GetStartCoordinates().Y == 5);
        }
Exemplo n.º 5
0
        public void EnsureEngineIsNotStartetTwice()
        {
            int called = 0;

            RandomMock.Setup(_ => _.CalculateStart(Options.MapX, Options.MapY))
            .Returns(() => {
                called++;
                return(StartCell);
            });
            GameEngine engine = new GameEngine(Options);

            engine.Start().Start();
            Assert.AreEqual(1, called);
        }
Exemplo n.º 6
0
        public void MakeMoveShouldMakeWinningMoveForXRandomly()
        {
            //arrange
            //setup a mock for the initial object..
            Move[]       initialGameMoveArray = new Move[1];
            Mock <IGame> initialGame          = new Mock <IGame>();

            initialGame
            .Setup(a => a.MoveHistory)
            .Returns(initialGameMoveArray);

            TicTacToeFactoryMock
            .Setup(a => a.NewGame(initialGameMoveArray))
            .Returns(GameMock.Object);

            //setup the game mock that will drive the rest of our choices
            List <Move> legalMoves = new List <Move>()
            {
                Move.Northern,
                Move.Center,
                Move.Southern
            };

            GameMock
            .Setup(a => a.GetLegalMoves())
            .Returns(legalMoves);

            GameMock
            .Setup(a => a.GameIsOver)
            .Returns(true);

            GameMock
            .Setup(a => a.CurrentPlayer)
            .Returns(Player.X);

            var callCount = 0;

            GameMock
            .Setup(a => a.GameState)
            .Returns(() =>
            {
                callCount++;
                switch (callCount - 1)
                {
                case 0:
                    return(GameState.OWin);

                case 1:
                    return(GameState.XWin);

                default:
                    return(GameState.Tie);
                }
            });

            //setup up our random mock
            RandomMock
            .Setup(a => a.Next(1))
            .Returns(0);

            //act
            BruteForce.MakeMove(initialGame.Object);

            //assert

            //random was called
            RandomMock.Verify(a => a.Next(1), Times.Once());

            //the center move was made
            GameMock
            .Verify(a => a.Move(Move.Center));
        }
Exemplo n.º 7
0
        public void MakeMoveShouldMakeCopyOfGame()
        {
            //arrange
            //setup a mock for the initial object..
            Move[]       initialGameMoveArray = new Move[1];
            Mock <IGame> initialGame          = new Mock <IGame>(MockBehavior.Strict);

            initialGame
            .Setup(a => a.MoveHistory)
            .Returns(initialGameMoveArray);

            initialGame
            .Setup(a => a.GameIsOver)
            .Returns(false);

            initialGame
            .Setup(a => a.Move(It.IsAny <Move>()));

            TicTacToeFactoryMock
            .Setup(a => a.NewGame(initialGameMoveArray))
            .Returns(GameMock.Object);

            //setup the game mock that will drive the rest of our choices
            List <Move> legalMoves = new List <Move>()
            {
                Move.Northern,
                Move.Center,
                Move.Southern
            };

            GameMock
            .Setup(a => a.GetLegalMoves())
            .Returns(legalMoves);

            GameMock
            .Setup(a => a.GameIsOver)
            .Returns(true);

            GameMock
            .Setup(a => a.CurrentPlayer)
            .Returns(Player.O);

            var callCount = 0;

            GameMock
            .Setup(a => a.GameState)
            .Returns(() =>
            {
                callCount++;
                switch (callCount - 1)
                {
                case 0:
                    return(GameState.XWin);

                case 1:
                    return(GameState.XWin);

                default:
                    return(GameState.XWin);
                }
            });

            //setup up our random mock
            RandomMock
            .Setup(a => a.Next(3))
            .Returns(0);

            //act
            BruteForce.MakeMove(initialGame.Object);

            //assert
            TicTacToeFactoryMock.Verify(a => a.NewGame(initialGameMoveArray), Times.Once());
        }