Exemplo n.º 1
0
        public void CanDrawBoardTest()
        {
            TTTBoard board = new TTTBoard();
            board.MakeMove(new Nought(), 0, 0);
            board.MakeMove(new Cross(), 2, 2);
            ConsoleBoardPainter painter = new ConsoleBoardPainter();

            board.PaintBoard(painter);
        }
Exemplo n.º 2
0
        public void MakeMoveInNonEmptyCell()
        {
            TTTBoard board = new TTTBoard();

            //Make a move on this board
            board.MakeMove(new TTTMove(2, 2));

            //Attempt to make another move in the same place as the last move, which should throw an InvalidMoveException
            Assert.Throws <InvalidMoveException>(() => board.MakeMove(new TTTMove(2, 2)));
        }
Exemplo n.º 3
0
        public void WinTestDownwardsDiagonal()
        {
            TTTBoard board = new TTTBoard();

            //Make moves such that player 1 should win with a downwards diagonal victory
            board.MakeMove(new TTTMove(0, 0));
            board.MakeMove(new TTTMove(0, 1));
            board.MakeMove(new TTTMove(1, 1));
            board.MakeMove(new TTTMove(2, 0));
            board.MakeMove(new TTTMove(2, 2));

            //Player 1 should have won the game
            Assert.AreEqual(1, board.Winner);
        }
Exemplo n.º 4
0
        public void WinTestHorizontal()
        {
            TTTBoard board = new TTTBoard();

            //Make moves such that player 1 should win with a horizontal victory
            board.MakeMove(new TTTMove(0, 2));
            board.MakeMove(new TTTMove(0, 0));
            board.MakeMove(new TTTMove(1, 2));
            board.MakeMove(new TTTMove(2, 0));
            board.MakeMove(new TTTMove(2, 2));

            //Player 1 should have won the game
            Assert.AreEqual(1, board.Winner);
        }
Exemplo n.º 5
0
        public void GetPossibleMovesOneMoveMade()
        {
            TTTBoard board = new TTTBoard();

            board.MakeMove(new TTTMove(1, 2));
            Assert.AreEqual(8, board.PossibleMoves().Count);
        }
Exemplo n.º 6
0
        public void MakeMoveTest()
        {
            //Create a new board and make a move in it
            TTTBoard board = new TTTBoard();

            board.MakeMove(new TTTMove(1, 0));

            //Check that the move was made correctly
            Assert.AreEqual(1, board.GetCell(1, 0));

            //Make a move on the board for the second player
            board.MakeMove(new TTTMove(2, 1));

            //Check that the move was made correctly
            Assert.AreEqual(2, board.GetCell(2, 1));
        }
Exemplo n.º 7
0
        public void NoWinnerTest()
        {
            TTTBoard board = new TTTBoard();

            //Make a move, if there is a winner, the winner flag will be set, but there is no winner, so it shouldn't
            board.MakeMove(new TTTMove(0, 0));

            //Check that the winner flag has not been set, as there is no winner
            Assert.AreEqual(-1, board.Winner);
        }
Exemplo n.º 8
0
        public void DrawTest()
        {
            TTTBoard board = new TTTBoard();

            //Make moves on the board until it is full and there is no winner
            board.MakeMove(new TTTMove(0, 0));
            board.MakeMove(new TTTMove(1, 1));
            board.MakeMove(new TTTMove(2, 2));
            board.MakeMove(new TTTMove(0, 1));
            board.MakeMove(new TTTMove(0, 2));
            board.MakeMove(new TTTMove(2, 0));
            board.MakeMove(new TTTMove(2, 1));
            board.MakeMove(new TTTMove(1, 2));
            board.MakeMove(new TTTMove(1, 0));

            //Check that the game has ended in a draw
            Assert.AreEqual(0, board.Winner);
        }
Exemplo n.º 9
0
        public void GetPossibleMovesFullBoard()
        {
            TTTBoard board = new TTTBoard();

            for (int y = 0; y < board.Height; y++)
            {
                for (int x = 0; x < board.Width; x++)
                {
                    board.MakeMove(new TTTMove(x, y));
                }
            }
            Assert.AreEqual(0, board.PossibleMoves().Count);
        }
Exemplo n.º 10
0
        public void DuplicateTest()
        {
            //Create a new board and make a move in it
            TTTBoard boardA = new TTTBoard();

            boardA.MakeMove(new TTTMove(1, 1));

            //Duplicate the board and store it in a new board instance
            TTTBoard boardB = (TTTBoard)boardA.Duplicate();

            //Ensure the move made before duplication is present in both boards
            Assert.AreEqual(1, boardA.GetCell(1, 1));
            Assert.AreEqual(1, boardB.GetCell(1, 1));

            //These two board instances should share no memory, lets prove it by making moves in each of them and checking the other
            boardA.MakeMove(new TTTMove(2, 0));
            Assert.AreEqual(2, boardA.GetCell(2, 0));
            Assert.AreEqual(0, boardB.GetCell(2, 0));

            boardB.MakeMove(new TTTMove(1, 2));
            Assert.AreEqual(0, boardA.GetCell(1, 2));
            Assert.AreEqual(2, boardB.GetCell(1, 2));
        }