Ejemplo n.º 1
0
        public void Play_PlayerWinsOnTenthTurn_PlayerWins()
        {
            // arrange
            var player1 = CreateFakePlayer();

            player1.Take10TurnsAt(BoardPosition.At(1, 1));

            var player2 = CreateFakePlayer();

            player2.TakeTurn(Arg.Any <IPlayerBoard>()).
            Returns(
                BoardPosition.At(0, 0),
                BoardPosition.At(0, 0),
                BoardPosition.At(0, 0),
                BoardPosition.At(0, 0),
                BoardPosition.At(0, 0),
                BoardPosition.At(0, 0),
                BoardPosition.At(0, 0),
                BoardPosition.At(0, 0),
                BoardPosition.At(0, 1),
                BoardPosition.At(0, 2));

            var game = new Game(player1, player2);

            // act
            game.Play();

            // assert
            Assert.That(game.Result, Is.EqualTo(GameStatus.Player2Wins));
        }
Ejemplo n.º 2
0
        public void Information_OutsideBoundary_ReturnsOutsideBoundaryMessage()
        {
            // arrange
            var move = new Move(new FakeBoard(), new FakePlayer(), BoardPosition.At(1, 2), MoveResult.OutsideBoardBoundary, moveNumber: 1);

            // act
            var output = move.Information();

            // assert
            Assert.That(output, Is.EqualTo("Position is outside board"));
        }
Ejemplo n.º 3
0
        public void MoveText_NormalMove_DisplaysMoveNormally()
        {
            // arrange
            var move = new Move(new FakeBoard(), new FakePlayer(), BoardPosition.At(1, 2), MoveResult.ValidMove, moveNumber: 1);

            // act
            var output = move.MoveText();

            // assert
            Assert.That(output, Is.EqualTo("FakePlayer plays at [1,2]"));
        }
Ejemplo n.º 4
0
        public void Information_PositionTaken_ReturnsPositionTakenMessage()
        {
            // arrange
            var move = new Move(new FakeBoard(), new FakePlayer(), BoardPosition.At(1, 2), MoveResult.PositionTaken, moveNumber: 1);

            // act
            var output = move.Information();

            // assert
            Assert.That(output, Is.EqualTo("Position already taken"));
        }
Ejemplo n.º 5
0
        public void Information_NormalMove_NoInformation()
        {
            // arrange
            var move = new Move(new FakeBoard(), new FakePlayer(), BoardPosition.At(1, 2), MoveResult.ValidMove, moveNumber: 1);

            // act
            var output = move.Information();

            // assert
            Assert.That(output, Is.EqualTo(string.Empty));
        }
Ejemplo n.º 6
0
        public void MoveText_Exception_DisplaysFailedMove()
        {
            // arrange
            var move = new Move(new FakeBoard(), new FakePlayer(), BoardPosition.At(1, 2), MoveResult.Exception, 0, "Problems!!");

            // act
            var output = move.MoveText();

            // assert
            Assert.That(output, Is.EqualTo("FakePlayer failed to play"));
        }
Ejemplo n.º 7
0
        public void MoveText_OutsideBoundary_DisplaysMoveNormally()
        {
            // arrange
            var move = new Move(new FakeBoard(), new FakePlayer(), BoardPosition.At(3, 4), MoveResult.OutsideBoardBoundary);

            // act
            var output = move.MoveText();

            // assert
            Assert.That(output, Is.EqualTo("FakePlayer plays at [3,4]"));
        }
Ejemplo n.º 8
0
        public void Information_Exception_DisplaysException()
        {
            // arrange
            var move = new Move(new FakeBoard(), new FakePlayer(), BoardPosition.At(1, 2), MoveResult.Exception, 0, "Problems!!");

            // act
            var output = move.Information();

            // assert
            Assert.That(output, Is.EqualTo("Exception: Problems!!"));
        }
Ejemplo n.º 9
0
        public void Information_Timeout_DisplaysTimeoutMessage()
        {
            // arrange
            var move = new Move(new FakeBoard(), new FakePlayer(), BoardPosition.At(1, 2), MoveResult.Timeout);

            // act
            var output = move.Information();

            // assert
            Assert.That(output, Is.EqualTo("Move timed out"));
        }
Ejemplo n.º 10
0
        public BoardPosition TakeTurn(IPlayerBoard board)
        {
            // let's see if anyone's played at 0,0...
            if (board.TokenAt(BoardPosition.At(0, 0)) == PlayerToken.None)
            {
                // No? Sweet! Let's play there.
                return(BoardPosition.At(0, 0));
            }

            // Sod it, I'm going to play there anyway..
            return(BoardPosition.At(0, 0));
        }
Ejemplo n.º 11
0
        public void PlayTurn_PlayerTakesAges_MoveNotAccepted()
        {
            // arrange
            var player1 = CreateFakePlayerWhichTakesAgesToPlay(BoardPosition.At(2, 2));
            var player2 = CreateFakePlayer();
            var game    = new Game(player1, player2);

            // act
            game.PlayTurn();

            // assert
            Assert.That(game.Moves[0].Board.TokenAt(BoardPosition.At(2, 2)) != GameToken.Player1);
        }
Ejemplo n.º 12
0
        public void PlayTurn_PlayerTakesAges_MoveResultSetToTimeout()
        {
            // arrange
            var player1 = CreateFakePlayerWhichTakesAgesToPlay(BoardPosition.At(2, 2));
            var player2 = CreateFakePlayer();
            var game    = new Game(player1, player2);

            // act
            game.PlayTurn();

            // assert
            Assert.That(game.Moves[0].Result, Is.EqualTo(MoveResult.Timeout));
        }
Ejemplo n.º 13
0
        public void PlayTurn_Called_PlayerGetsPersonalCopyOfBoard()
        {
            // arrange
            var player1 = CreateFakePlayer();

            player1.TakeTurn(Arg.Any <IPlayerBoard>()).Returns(new BoardPosition(1, 1));
            var player2 = CreateFakePlayer();
            var game    = new Game(player1, player2);

            // act
            game.PlayTurn();

            // assert
            player2.Received().TakeTurn(Arg.Is <PlayerBoard>(x => x.TokenAt(BoardPosition.At(1, 1)) == PlayerToken.Opponent));
        }
Ejemplo n.º 14
0
        private static bool EmptySpacesExist(CrossesBoard board)
        {
            for (int rowIndex = 0; rowIndex < CrossesBoard.BOARD_SIZE; rowIndex++)
            {
                for (int columnIndex = 0; columnIndex < CrossesBoard.BOARD_SIZE; columnIndex++)
                {
                    if (board.TokenAt(BoardPosition.At(columnIndex, rowIndex)) == GameToken.None)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 15
0
        public void Play_GameStillRunningAfter10Rounds_GameMessageSet()
        {
            // arrange
            var player1 = CreateFakePlayer();

            player1.Take10TurnsAt(BoardPosition.At(1, 1));

            var player2 = CreateFakePlayer();

            player2.Take10TurnsAt(BoardPosition.At(1, 1));

            var game = new Game(player1, player2);

            // act
            game.Play();

            // assert
            Assert.That(game.Message, Is.EqualTo("Game stopped after 10 rounds"));
        }
Ejemplo n.º 16
0
        public void Play_GameStillRunningAfter10Rounds_DeclaredADraw()
        {
            // arrange
            var player1 = CreateFakePlayer();

            player1.Take10TurnsAt(BoardPosition.At(1, 1));

            var player2 = CreateFakePlayer();

            player2.Take10TurnsAt(BoardPosition.At(1, 1));

            var game = new Game(player1, player2);

            // act
            game.Play();

            // assert
            Assert.That(game.Result, Is.EqualTo(GameStatus.Draw));
        }
Ejemplo n.º 17
0
        public IPlayerBoard For(GameToken player)
        {
            var playerTokenFor = new Dictionary <GameToken, PlayerToken> {
                { GameToken.Player1, player == GameToken.Player1 ? PlayerToken.Me : PlayerToken.Opponent },
                { GameToken.Player2, player == GameToken.Player2 ? PlayerToken.Me : PlayerToken.Opponent },
                { GameToken.None, PlayerToken.None }
            };

            PlayerBoard boardForPlayer = new PlayerBoard();

            for (int columns = 0; columns < BOARD_SIZE; columns++)
            {
                for (int rows = 0; rows < BOARD_SIZE; rows++)
                {
                    var gameToken = _board[columns, rows];
                    boardForPlayer.SetToken(playerTokenFor[gameToken], BoardPosition.At(columns, rows));
                }
            }

            return(boardForPlayer);
        }
Ejemplo n.º 18
0
 public BoardPosition TakeTurn(IPlayerBoard board)
 {
     Console.WriteLine("************** I'm a ChattyBot, hear me ROAR!  ************");
     return(BoardPosition.At(2, 2));
 }
Ejemplo n.º 19
0
 public BoardPosition TakeTurn(IPlayerBoard board)
 {
     return(BoardPosition.At(0, 0));
 }