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)
""" Runs the monte carlo simulation for specified number of times """ from monte_carlo_tictactoe import mc_move from tictactoe_board import (PLAYERX, switch_player, TicTacToeBoard) BOARD = TicTacToeBoard(3, False, None) NUM_TRIALS = 500 PLAYER = PLAYERX win = None while not win: MOVE = mc_move(BOARD, PLAYER, NUM_TRIALS) BOARD.move(MOVE[0], MOVE[1], PLAYER) PLAYER = switch_player(PLAYER) print BOARD.__str__() + '\n' win = BOARD.evaluate_win_status() print "win: " + str(win)