def performance_test(): """ the performance test borrowed from http://www.codeskulptor.org/#user41_rAX7Nukse9WzOOV.py """ time.time() start = time.time() provided.play_game(mc_move, NTRIALS, False) print str(provided.play_game)+": \t" + str( (time.time() - start) )
mc_update_scores(scores, board1, player) num -= 1 next_move = get_best_move(board, scores) return next_move # Test game with the console or the GUI. # Uncomment whichever you prefer. # Both should be commented out when you submit for # testing to save time. provided.play_game(mc_move, NTRIALS, False) # poc_ttt_gui.run_gui(3, provided.PLAYERX, mc_move, NTRIALS, False) #import user35_PIk21NjpAa_0 as tests #tests.test_mc_trial(mc_trial) # tests for mc_trial #tests.test_mc_update_scores(mc_update_scores, MCMATCH, MCOTHER) # tests for mc_update_scores #tests.test_get_best_move(get_best_move) # tests for get_best_move #tests.test_mc_move(mc_move, NTRIALS)
if player == provided.PLAYERX: if score < result[0]: score = max(score, result[0]) final_move = _move else: if score > result[0]: score = min(score, result[0]) final_move = _move return score, final_move def move_wrapper(board, player, trials): """ Wrapper to allow the use of the same infrastructure that was used for Monte Carlo Tic-Tac-Toe. """ move = mm_move(board, player) #assert move[1] != (-1, -1), "returned illegal move (-1, -1)" return move[1] # Test game with the console or the GUI. # Uncomment whichever you prefer. # Both should be commented out when you submit for # testing to save time. provided.play_game(move_wrapper, 1, False) #poc_ttt_gui.run_gui(3, provided.PLAYERO, move_wrapper, 1, False)
all_move =[] for each in board.get_empty_squares(): temp = board.clone() temp.move(each[0], each[1], player) all_move.append([minmax(temp, provided.switch_player(player)), each]) if player == provided.PLAYERX: all_move.sort(key = lambda x: x[0], reverse=True) else: all_move.sort(key = lambda x: x[0]) return all_move[0][0], all_move[0][1] def move_wrapper(board, player, trials): """ Wrapper to allow the use of the same infrastructure that was used for Monte Carlo Tic-Tac-Toe. """ move = mm_move(board, player) assert move[1] != (-1, -1), "returned illegal move (-1, -1)" return move[1] # Test game with the console or the GUI. # Uncomment whichever you prefer. # Both should be commented out when you submit for # testing to save time. provided.play_game(move_wrapper, 1, False) poc_ttt_gui.run_gui(3, provided.PLAYERO, move_wrapper, 1, False)
""" dimension = board.get_dim() scores = [[0 for dummy in range(dimension)] for dummy in range(dimension)] for dummy in range(trials): board_copy = board.clone() mc_trial(board_copy, player) mc_update_scores(scores, board_copy, player) return get_best_move(board, scores) # Test game with the console or the GUI Uncomment whichever # you prefer. Both should be commented out when you submit # for testing to save time. provided.play_game(mc_move, NTRIALS, False) poc_ttt_gui.run_gui(3, provided.PLAYERX, mc_move, NTRIALS, False) # # Testing code # test_game = provided.TTTBoard(3) # test_dim = test_game.get_dim() # test_scores = [[0 for emptycol in range(test_dim)] # for emptyrow in range(test_dim)] # # test mc_trial() # mc_trial(test_game, provided.PLAYERX) # print str(test_game) # print "Winner:", test_game.check_win(), "\n" # # test mc_update_scores # mc_update_scores(test_scores, test_game, provided.PLAYERX)
return res ###Test game with the console or the GUI. AI_VS_AI_GAMES = 20 winners = [] lookup = {provided.PLAYERX: "Monte carol", provided.PLAYERO: "minMax"} win1 = 0 win2 = 0 tie = 0 a1_total_t = 0 a2_total_t = 0 for i in range(AI_VS_AI_GAMES): # two AI test print("test", i) winner, a1_time, a2_time = provided.play_game(mc_move, NTRIALS, minMaxMove, DEPTH, False) a1_total_t += a1_time a2_total_t += a2_time if winner == provided.PLAYERX: win1 += 1 elif winner == provided.PLAYERO: win2 += 1 else: tie += 1 print("%d %d %d\n" % (win1, tie, win2)) # poc_ttt_gui.run_gui(3, provided.PLAYERX, mc_move, NTRIALS, False) # just run minmax # poc_ttt_gui.run_gui(3, provided.PLAYERX, minMaxMove, DEPTH, False)