def test(self):
        board = TicTacToeBoard(3, False, None)
        original_state = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
        self.assertEqual(board.board, original_state)

        mc_trial(board, PLAYERX)
        self.assertNotEqual(board.board, original_state)
        self.assertNotEqual(board.evaluate_win_status(), None)
    def test(self):
        tictactoe_board = TicTacToeBoard(3, False, None)
        self.assertEqual(tictactoe_board.board,
                         [[0, 0, 0], [0, 0, 0], [0, 0, 0]])

        tictactoe_board = TicTacToeBoard(5, False, None)
        self.assertEqual(tictactoe_board.board,
                         [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0],
                          [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
    def test(self):
        tictactoe_board = TicTacToeBoard(4, False, None)
        tictactoe_board.board[0][0] = 1
        tictactoe_board.board[1][2] = 2
        tictactoe_board.board[0][1] = 1
        tictactoe_board.board[2][2] = 2
        tictactoe_board.board[3][1] = 1
        tictactoe_board.board[2][3] = 2

        self.assertEqual(tictactoe_board.uleft_bright(), [1, 0, 2, 0])
        self.assertEqual(tictactoe_board.bleft_uright(), [0, 0, 2, 0])
    def test(self):
        tictactoe_board = TicTacToeBoard(4, False, None)
        tictactoe_board.move(0, 0, PLAYERX)
        tictactoe_board.move(3, 0, PLAYERX)
        tictactoe_board.move(1, 2, PLAYERO)
        tictactoe_board.move(1, 3, PLAYERO)
        tictactoe_board.move(1, 3, PLAYERX)

        self.assertEqual(tictactoe_board.square(0, 0), PLAYERX)
        self.assertEqual(tictactoe_board.square(3, 0), PLAYERX)
        self.assertEqual(tictactoe_board.square(1, 2), PLAYERO)
        self.assertEqual(tictactoe_board.square(1, 3), PLAYERO)
    def test(self):
        tictactoe_board = TicTacToeBoard(4, False, None)
        tictactoe_board.board[0][0] = 1
        tictactoe_board.board[1][2] = 2
        tictactoe_board.board[0][1] = 1
        tictactoe_board.board[2][2] = 2
        tictactoe_board.board[3][1] = 1
        tictactoe_board.board[2][3] = 2

        self.assertEqual(
            tictactoe_board.column_grid(),
            [[1, 0, 0, 0], [1, 0, 0, 1], [0, 2, 2, 0], [0, 0, 2, 0]])
    def test(self):
        board = TicTacToeBoard(3, False, None)

        index_grid = [[(row, col) for col in range(board.dimension)]
                      for row in range(board.dimension)]
        index_list = []
        for l_list in index_grid:
            index_list += l_list

        self.assertIsInstance(mc_move(board, PLAYERO, 30), tuple)
        self.assertIn(mc_move(board, PLAYERO, 30), index_list)
    def test(self):
        tictactoe_board = TicTacToeBoard(4, False, None)
        tictactoe_board.board[0][0] = 1
        tictactoe_board.board[1][2] = 2

        self.assertEqual(tictactoe_board.square(0, 0), PLAYERX)
        self.assertEqual(tictactoe_board.square(1, 2), PLAYERO)
        self.assertEqual(tictactoe_board.square(0, 1), EMPTY)
    def test(self):
        scores = [[3, -3, 5], [-2, 7, 0], [4, -1, 3]]
        board = TicTacToeBoard(3, False, None)
        board.board = [[0, 2, 1], [0, 1, 2], [1, 2, 1]]
        mc_update_scores(scores, board, PLAYERX)

        self.assertEqual(scores, [[3, -4, 6], [-2, 8, -1], [5, -2, 4]])

        scores = [[4, -3, 5], [-2, 7, -3], [4, -1, 3]]
        board = TicTacToeBoard(3, False, None)
        board.board = [[2, 2, 1], [2, 1, 2], [2, 1, 1]]
        mc_update_scores(scores, board, PLAYERO)

        self.assertEqual(scores, [[5, -2, 4], [-1, 6, -2], [5, -2, 2]])
 def test(self):
     tictactoe_board = TicTacToeBoard(5, False, None)
     tictactoe_board.dimension = 3
     new_board = tictactoe_board.new_board()
     self.assertEqual(new_board, [[0, 0, 0], [0, 0, 0], [0, 0, 0]])
    def test(self):
        scores = [[3, -3, 5], [-2, 7, 0], [4, -1, 3]]
        board = TicTacToeBoard(3, False, None)
        board.board = [[0, 2, 1], [0, 1, 2], [1, 2, 1]]

        self.assertEqual(get_best_move(board, scores), (0, 0))

        board.board = [[0, 2, 1], [0, 0, 2], [1, 2, 1]]

        self.assertEqual(get_best_move(board, scores), (1, 1))

        board.board = [[2, 0, 1], [2, 1, 2], [1, 0, 1]]

        self.assertEqual(get_best_move(board, scores), (2, 1))

        board.board = [[0, 2, 1], [0, 1, 2], [1, 0, 0]]

        self.assertIn(get_best_move(board, scores), ((0, 0), (2, 2)))

        board.board = [[1, 2, 1], [2, 1, 2], [1, 2, 1]]

        self.assertEqual(get_best_move(board, scores), None)

        scores = [[1, 2, 3], [7, 8, 9], [4, 5, 6]]
        board.board = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]

        self.assertEqual(get_best_move(board, scores), (1, 2))

        scores = [[1, 2, 10], [7, 8, 9], [4, 5, 6]]
        board.board = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]

        self.assertEqual(get_best_move(board, scores), (0, 2))

        board2 = TicTacToeBoard(2, False, None)
        scores = [[1, 2], [7, 8]]
        board2.board = [[0, 0], [0, 0]]

        self.assertEqual(get_best_move(board2, scores), (1, 1))
    def test(self):
        board = TicTacToeBoard(3, False, None)
        board.board = [[2, 2, 1], [2, 1, 2], [2, 1, 1]]

        self.assertEqual(get_score_values(board, PLAYERO), (1, -1))
        self.assertEqual(get_score_values(board, PLAYERX), (-1, 1))
from cv_tictactoe_board import (PLAYERO, PLAYERX, switch_player,
                                TicTacToeBoard)
from monte_carlo_tictactoe import (get_best_move, mc_move)

board = TicTacToeBoard(3, False, None)
player = PLAYERX
win = None

while not win:
    move = mc_move(board, player, 500)
    board.move(move[0], move[1], player)
    player = switch_player(player)
    print board.__str__() + '\n'
    win = board.evaluate_win_status()

print "win: " + str(win)
    def test(self):
        tictactoe_board = TicTacToeBoard(2, False, None)

        self.assertEqual(tictactoe_board.get_empty_squares(), [(0, 0), (0, 1),
                                                               (1, 0), (1, 1)])

        tictactoe_board = TicTacToeBoard(4, False, None)
        tictactoe_board.board[0][0] = 1
        tictactoe_board.board[1][2] = 2
        tictactoe_board.board[2][1] = 1

        self.assertEqual(tictactoe_board.get_empty_squares(), [(0, 1), (0, 2),
                                                               (0, 3), (1, 0),
                                                               (1, 1), (1, 3),
                                                               (2, 0), (2, 2),
                                                               (2, 3), (3, 0),
                                                               (3, 1), (3, 2),
                                                               (3, 3)])

        tictactoe_board.board[1][3] = 2
        tictactoe_board.board[3][0] = 2
        tictactoe_board.board[2][3] = 1

        self.assertEqual(tictactoe_board.get_empty_squares(), [(0, 1), (0, 2),
                                                               (0, 3), (1, 0),
                                                               (1, 1), (2, 0),
                                                               (2, 2), (3, 1),
                                                               (3, 2), (3, 3)])
 def test(self):
     board = TicTacToeBoard(5, False, None)
     clone = board.clone()
     self.assertNotEqual(clone, board)
 def test(self):
     board = TicTacToeBoard(5, False, None)
     self.assertEqual(board.get_dim(), 5)
 def test(self):
     tictactoe_board = TicTacToeBoard(3, False, None)
     self.assertEqual(
         tictactoe_board.__str__(),
         "   |   |  \n-----------\n   |   |  \n-----------\n   |   |  ")
    def test(self):
        tictactoe_board = TicTacToeBoard(3, False, None)
        tictactoe_board.board = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]

        self.assertEqual(tictactoe_board.evaluate_win_status(), None)

        tictactoe_board.board = [[0, 0, 2], [0, 2, 0], [1, 1, 1]]

        self.assertEqual(tictactoe_board.evaluate_win_status(), PLAYERX)

        tictactoe_board.board = [[2, 0, 2], [2, 1, 0], [2, 1, 1]]

        self.assertEqual(tictactoe_board.evaluate_win_status(), PLAYERO)

        tictactoe_board.board = [[1, 0, 2], [0, 1, 2], [2, 1, 1]]

        self.assertEqual(tictactoe_board.evaluate_win_status(), PLAYERX)

        tictactoe_board.board = [[0, 0, 2], [0, 2, 0], [2, 1, 1]]

        self.assertEqual(tictactoe_board.evaluate_win_status(), PLAYERO)

        tictactoe_board.board = [[1, 1, 2], [2, 2, 1], [1, 2, 1]]

        self.assertEqual(tictactoe_board.evaluate_win_status(), DRAW)
    def test(self):
        tictactoe_board = TicTacToeBoard(4, False, None)
        tictactoe_board.board[0][0] = 1
        tictactoe_board.board[1][2] = 2
        tictactoe_board.board[0][1] = 1

        uleft_bright = tictactoe_board.uleft_bright()
        bleft_uright = tictactoe_board.bleft_uright()

        self.assertEqual(tictactoe_board.evaluate_diagonal_win(uleft_bright),
                         [])
        self.assertEqual(tictactoe_board.evaluate_diagonal_win(bleft_uright),
                         [])

        tictactoe_board.board[1][1] = 1
        tictactoe_board.board[2][1] = 1
        tictactoe_board.board[2][2] = 1
        tictactoe_board.board[3][3] = 1

        uleft_bright = tictactoe_board.uleft_bright()

        self.assertEqual(tictactoe_board.evaluate_diagonal_win(uleft_bright),
                         [PLAYERX])

        tictactoe_board.board[2][1] = 2
        tictactoe_board.board[3][0] = 2
        tictactoe_board.board[0][3] = 2

        bleft_uright = tictactoe_board.bleft_uright()

        self.assertEqual(tictactoe_board.evaluate_diagonal_win(bleft_uright),
                         [PLAYERO])
    def test(self):
        tictactoe_board = TicTacToeBoard(4, False, None)
        tictactoe_board.board[0][0] = 1
        tictactoe_board.board[1][2] = 2
        tictactoe_board.board[0][1] = 1

        column_grid = tictactoe_board.column_grid()
        row_grid = tictactoe_board.board

        self.assertEqual(tictactoe_board.evaluate_grid_win(column_grid), [])
        self.assertEqual(tictactoe_board.evaluate_grid_win(row_grid), [])

        tictactoe_board.board[1][1] = 1
        tictactoe_board.board[2][1] = 1
        tictactoe_board.board[2][2] = 2
        tictactoe_board.board[3][1] = 1
        tictactoe_board.board[2][3] = 2

        column_grid = tictactoe_board.column_grid()

        self.assertEqual(tictactoe_board.evaluate_grid_win(column_grid),
                         [PLAYERX])

        tictactoe_board.board[2][1] = 2
        tictactoe_board.board[2][0] = 2

        row_grid = tictactoe_board.board

        self.assertEqual(tictactoe_board.evaluate_grid_win(row_grid),
                         [PLAYERO])