public void PlayersMustMoveWithinTheTopLeftBoundsOfTheBoard()
        {
            var naughts = new TurnByTurnPlayerStub();
            var game = new TicTacToeGame(naughts, null);

            naughts.Next(0, 0);

            Assert.Throws<InvalidMoveException>(() => game.PlayTurn());
        }
        public void PlayerAlwaysWinsOrDrawsIfStartsTheGame()
        {
            var naughts = new TurnByTurnPlayerStub();
            var crosses = new MiniMaxPlayer(naughts);

            var result = PlayAllPossibleGames(new TicTacToeBoard(), crosses, naughts);

            Assert.That(result.Losses, Is.EqualTo(0));
        }
        public void NaughtsStartsTheGame()
        {
            var naughts = new TurnByTurnPlayerStub();
            var game = new TicTacToeGame(naughts, null);

            naughts.Next(1, 1);
            game.PlayTurn();

            Assert.That(game.PlayerOnSquare(1, 1), Is.EqualTo(naughts));
        }
        public void PlayersAlternateTurns()
        {
            var naughts = new TurnByTurnPlayerStub();
            var crosses = new TurnByTurnPlayerStub();
            var game = new TicTacToeGame(naughts, crosses);

            naughts.Next(1, 1);
            game.PlayTurn();

            Assert.That(game.CurrentPlayer, Is.EqualTo(crosses));
        }
Ejemplo n.º 5
0
        public void MakeWinningMove()
        {
            var naughts = new TurnByTurnPlayerStub();
            var crosses = new MiniMaxPlayer(naughts);
            var board = new TicTacToeBoard(new ITicTacToePlayer[]
            {
                naughts, null, crosses,
                null, naughts, null,
                naughts, null, crosses
            });

            var position = crosses.PlayTurn(board);
            Assert.That(position, Is.EqualTo(new BoardPosition(2, 3)));
        }
Ejemplo n.º 6
0
        public void FindBestStartingMove()
        {
            var naughts = new TurnByTurnPlayerStub();
            var crosses = new MiniMaxPlayer(naughts);
            var board = new TicTacToeBoard(new ITicTacToePlayer[]
            {
                null, null, null,
                null, null, null,
                null, null, null
            });

            var position = crosses.PlayTurn(board);
            Assert.That(position, Is.EqualTo(new BoardPosition(1, 1)));
        }
        public void PlayersTurnIsNotOverUntilTheyMakeAValidMove()
        {
            var naughts = new TurnByTurnPlayerStub();
            var crosses = new TurnByTurnPlayerStub();
            var game = new TicTacToeGame(naughts, crosses);

            naughts.Next(1, 1);
            game.PlayTurn();

            crosses.Next(1, 1);
            game.PlayTurn();

            Assert.That(game.CurrentPlayer, Is.EqualTo(crosses));
        }
        public void OnlyOnePlayerCanClaimEachSquare()
        {
            var naughts = new TurnByTurnPlayerStub();
            var crosses = new TurnByTurnPlayerStub();
            var game = new TicTacToeGame(naughts, crosses);

            naughts.Next(1, 1);
            game.PlayTurn();

            crosses.Next(1, 1);
            game.PlayTurn();

            Assert.That(game.PlayerOnSquare(1, 1), Is.EqualTo(naughts));
        }
        public void PlayerAlwaysWinsOrDrawsIfOtherPlayerStartsTheGame()
        {
            var naughts = new TurnByTurnPlayerStub();
            var crosses = new MiniMaxPlayer(naughts);

            var board = new TicTacToeBoard();
            var tally = ScoreTally.Start;
            foreach (var square in board.VacantSquares)
            {
                var results = PlayAllPossibleGames(board.UpdateBoard(square, naughts), crosses, naughts);
                tally = tally + results;
            }

            Assert.That(tally.Losses, Is.EqualTo(0));
        }