示例#1
0
        public void Test_Board_GameStatus_OWon()
        {
            var boardString = "XXX|OOO|.XX|OXX|O..|OOO|OXO|..O|.OO|OXX|OOO|XOO|XXX|OX.|.XX|.O.|O..|OO.|O..|OOO|.OX|XXX|...|...|..O|XXO|XXX";
            var macroboard  = "TOO|XOT|XOX";
            var board       = new UltimateBoard();

            board.ParseFromString(boardString);
            board.ParseMacroboardFromString(macroboard);

            // Tie
            Assert.IsTrue(board.GetGameStatus() == UltimateBoard.GameStatus.OWon);
        }
示例#2
0
        public void Test_Board_GameStatus_MoreMovesAvailable()
        {
            var boardString = "XOX|XXX|.XX|OXX|O..|OOO|OXO|..O|.OO|OXX|OOO|XOO|XXX|OX.|.XX|.O.|O..|OO.|O..|OOO|.OX|XXX|...|...|..O|XXO|XXX";
            var macroboard  = "TXO|XOA|XOX";
            var board       = new UltimateBoard();

            board.ParseFromString(boardString);
            board.ParseMacroboardFromString(macroboard);

            // More moves available in center-right of microboard
            Assert.IsTrue(board.GetGameStatus() == UltimateBoard.GameStatus.MovesAvailable);
        }
示例#3
0
        public void Test_Board_MakeMove_OccupiedPosition()
        {
            var boardString = "XOX|XXX|.XX|OXX|O..|OOO|OXO|..O|.OO|OXX|OOO|XOO|XXX|OX.|.XX|.O.|O..|OO.|O..|OOO|.OX|XXX|...|...|..O|XXO|XXX";
            var board       = new UltimateBoard();

            board.ParseFromString(boardString);

            // This position is occupied
            var move = new Move(1, 0);

            board.MakeMove(move, UltimateBoard.PlayerX);
        }
示例#4
0
        public void Test_Board_MakeMove_TieMove()
        {
            var boardString = "X.X|XXX|.XX|OXX|O..|OOO|OXO|..O|.OO|OXX|OOO|XOO|XXX|OX.|.XX|.O.|O..|OO.|O..|OOO|.OX|XXX|...|...|..O|XXO|XXX";
            var board       = new UltimateBoard();

            board.ParseFromString(boardString);

            // Tie the upper-left corner of microboard
            var move = new Move(1, 0);

            board.MakeMove(move, UltimateBoard.PlayerO);
            Assert.IsTrue(board.Macroboard[0, 0] == UltimateBoard.Tied);
        }
示例#5
0
        public void Test_Board_MakeMove_PlayerXWins()
        {
            // Make winning move in upper-left microboard
            var boardString = "X.X|XXX|.XX|OXX|O..|OOO|OXO|..O|.OO|OXX|OOO|XOO|XXX|OX.|.XX|.O.|O..|OO.|O..|OOO|.OX|XXX|...|...|..O|XXO|XXX";
            var board       = new UltimateBoard();

            board.ParseFromString(boardString);

            // Win the microboard
            var move = new Move(1, 0);

            board.MakeMove(move, UltimateBoard.PlayerX);

            // X won upper-left corner of macroboard
            Assert.IsTrue(board.Macroboard[0, 0] == UltimateBoard.PlayerX);
        }
示例#6
0
        public void Test_Board_IsWinnerMicroBoard()
        {
            var boardString = "XOX|XXX|.XX|OXX|O..|OOO|OXO|..O|.OO|OXX|OOO|XOO|XXX|OX.|.XX|.O.|O..|OO.|O..|OOO|.OX|XXX|...|...|..O|XXO|XXX";
            var board       = new UltimateBoard();

            board.ParseFromString(boardString);
            var results = "TXO|XO?|XOX";

            int count = 0;

            for (int y = 0; y < UltimateBoard.Rows / 3; y++)
            {
                for (int x = 0; x < UltimateBoard.Cols / 3; x++)
                {
                    string help = "[" + x + "," + y + "] winner should be is " + results[count];

                    if (results[count] == 'T' || results[count] == '?')
                    {
                        // No winner if tied or undecided
                        Assert.IsFalse(board.IsWinnerMicroBoard(board.Board, x, y, UltimateBoard.PlayerX), help);
                        Assert.IsFalse(board.IsWinnerMicroBoard(board.Board, x, y, UltimateBoard.PlayerO), help);
                    }
                    else if (results[count] == 'X')
                    {
                        Assert.IsTrue(board.IsWinnerMicroBoard(board.Board, x, y, UltimateBoard.PlayerX), help);
                        Assert.IsFalse(board.IsWinnerMicroBoard(board.Board, x, y, UltimateBoard.PlayerO), help);
                    }
                    else if (results[count] == 'O')
                    {
                        Assert.IsFalse(board.IsWinnerMicroBoard(board.Board, x, y, UltimateBoard.PlayerX), help);
                        Assert.IsTrue(board.IsWinnerMicroBoard(board.Board, x, y, UltimateBoard.PlayerO), help);
                    }
                    count++;
                }

                // Skip vertical bar
                count++;
            }
        }
示例#7
0
        public void Text_Board_IsTieMicroBoard()
        {
            var boardString = "XOX|XXX|.XX|OXX|O..|OOO|OXO|..O|.OO|OXX|OOO|XOO|XXX|OX.|.XX|.O.|O..|OO.|O..|OOO|.OX|XXX|...|...|..O|XXO|XXX";
            var board       = new UltimateBoard();

            board.ParseFromString(boardString);

            for (int y = 0; y < Field.Rows / 3; y++)
            {
                for (int x = 0; x < Field.Cols / 3; x++)
                {
                    if (x == 0 && y == 0)
                    {
                        Assert.IsTrue(board.IsTieMicroBoard(board.Board, x, y),
                                      "[" + x + "," + y + "]");
                    }
                    else
                    {
                        Assert.IsFalse(board.IsTieMicroBoard(board.Board, x, y),
                                       "[" + x + "," + y + "]");
                    }
                }
            }
        }