def agentvsagentloop(agent1, agent2): """ Pit two agents against eachother """ print("") agent1_wins = 0 agent2_wins = 0 for i in range(10): try: r = agent1() p = agent2() game = Board(r, p, 7, 7) output_b = game.copy() winner, move_history, termination = game.play_isolation( time_limit=1000, print_moves=False) print("\n", winner, " has won. Reason: ", termination) if winner == "CustomPlayerTest - Q1": agent1_wins += 1 else: agent2_wins += 1 # Uncomment to see game # print game_as_text(winner, move_history, termination, output_b) except NotImplementedError: print('CustomPlayer Test: Not Implemented') except: print('CustomPlayer Test: ERROR OCCURRED') print(traceback.format_exc()) print("agent 2 win ration: ", agent2_wins / 10) print()
def testMiniMax(): try: """Example test to make sure your minimax works, using the #computer_player_moves - opponent_moves evaluation function.""" # create dummy 3x3 board p1 = RandomPlayer() p2 = CustomPlayerAB(search_depth=3) #p2 = HumanPlayer() b = Board(p1, p2, 5, 5) b.__board_state__ = [[0, 21, 0, 0, 0], [0, 0, 11, 0, 0], [0, 0, 12, 0, 0], [0, 0, 0, 0, 0], [0, 22, 0, 0, 0]] b.__last_queen_move__["queen11"] = (1, 2) b.__last_queen_move__["queen21"] = (0, 1) b.__last_queen_move__["queen12"] = (2, 2) b.__last_queen_move__["queen22"] = (4, 1) b.move_count = 4 output_b = b.copy() winner, move_history, queen_history, termination = b.play_isolation( 1000, True) print 'Minimax Test: Runs Successfully' # Uncomment to see example game print game_as_text(winner, move_history, queen_history, b.output_history, termination, output_b) except NotImplementedError: print 'Minimax Test: Not Implemented' except: print 'Minimax Test: ERROR OCCURRED' print traceback.format_exc()
def test_case1(): player1 = MinimaxPlayer(search_depth=1, score_fn=open_move_score) player2 = GreedyPlayer() game = Board(player1, player2, 9, 9) game._board_state = [0, 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 1, 1, 0, 0, 1, 0, 0, \ 0, 0, 0, 0, 1, 1, 0, 0, 0, \ 0, 1, 0, 1, 1, 1, 0, 0, 0, \ 0, 0, 1, 0, 1, 0, 0, 0, 0, \ 0, 0, 1, 1, 1, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 37, 57] print('Current game') print(game.to_string()) print('Active player {}'.format(game.active_player)) print('Legal moves\n\t{}'.format(game.get_legal_moves())) time_limit = 10 time_millis = lambda: 1000 * timeit.default_timer() move_start = time_millis() time_left = lambda: 20 game_copy = game.copy() print('Next move: \n\t{}'.format(game.active_player.get_move(game_copy, time_left))) print('Expected move is (5,5), please verify!!!')
class Game: def __init__(self): self.human_player = None # it's the human player self.ia_player = CustomPlayer(method='alphabeta', iterative=False, score_fn=custom_score_knight_tour) self.board = Board(self.human_player, self.ia_player) def do_human_move(self, move): if self.board.active_player != self.human_player: raise WrongPlayer legal_player_moves = self.board.get_legal_moves(self.board.active_player) if not(move in legal_player_moves): raise InvalidMove("{} not found in {}".format(move, legal_player_moves)) self.board.apply_move(move) def do_ia_move(self, time_limit=TIME_LIMIT_MILLIS): if self.board.active_player != self.ia_player: raise WrongPlayer legal_player_moves = self.board.get_legal_moves(self.board.active_player) curr_time_millis = lambda: 1000 * timeit.default_timer() move_start = curr_time_millis() time_left = lambda : time_limit - (curr_time_millis() - move_start) game_copy = self.board.copy() curr_move = self.board.active_player.get_move(game_copy, legal_player_moves, time_left) move_end = time_left() self.board.apply_move(curr_move) return curr_move def display_board(self): print(self.board.to_string())
def test_case2(state, alpha, beta): player1 = AlphaBetaPlayer(search_depth=2, score_fn = open_move_score) player2 = GreedyPlayer() game = Board(player1, player2, 9, 9) game._board_state = state time_limit = 150 time_millis = lambda: 1000 * timeit.default_timer() move_start = time_millis() time_left = lambda : time_limit - (time_millis() - move_start) game_copy = game.copy() player1.time_left = time_left print('Next move: \n\t{}'.format(player1.alphabeta(game_copy, 2, alpha, beta))) print('Time left/limit ({:.2f}/{:.2f}) ms'.format(time_left(), time_limit))
def testCustomABPlayRandom(): """Example test you can run to make sure your AI does better than random.""" try: r = CustomPlayerAB(search_depth=10) h = RandomPlayer() game = Board(r, h, 7, 7) output_b = game.copy() winner, move_history, queen_history, termination = game.play_isolation( 1000, True) game.print_board() print game_as_text(winner, move_history, queen_history, game.output_history, termination, output_b) except NotImplementedError: print 'CustomPlayer Test: Not Implemented' except: print 'CustomPlayer Test: ERROR OCCURRED' print traceback.format_exc()
def beatRandom(yourAgent): """Example test you can run to make sure your AI does better than random.""" print("") try: r = RandomPlayer() p = yourAgent() game = Board(r, p, 7, 7) output_b = game.copy() winner, move_history, termination = game.play_isolation( time_limit=1000, print_moves=True) print("\n", winner, " has won. Reason: ", termination) # Uncomment to see game # print game_as_text(winner, move_history, termination, output_b) except NotImplementedError: print('CustomPlayer Test: Not Implemented') except: print('CustomPlayer Test: ERROR OCCURRED') print(traceback.format_exc()) print()
def agentvsagent(agent1, agent2): """ Pit two agents against eachother """ print("") try: r = agent1() p = agent2() game = Board(r, p, 7, 7) output_b = game.copy() winner, move_history, termination = game.play_isolation( time_limit=1000, print_moves=True) print("\n", winner, " has won. Reason: ", termination) # Uncomment to see game # print game_as_text(winner, move_history, termination, output_b) except NotImplementedError: print('CustomPlayer Test: Not Implemented') except: print('CustomPlayer Test: ERROR OCCURRED') print(traceback.format_exc()) print()
your minimax works, using the #my_moves evaluation function.""" from isolation import Board, game_as_text from player_submission import CustomPlayer if __name__ == "__main__": # create dummy 3x3 board p1 = CustomPlayer(search_depth=3) p2 = CustomPlayer() b = Board(p1, p2, 3, 3) b.__board_state__ = [[0, 2, 0], [0, 0, 1], [0, 0, 0]] b.__last_player_move__[p1] = (1, 2) b.__last_player_move__[p2] = (0, 1) b.move_count = 2 output_b = b.copy() # use minimax to determine optimal move # sequence for player 1 winner, move_history, termination = b.play_isolation() print game_as_text(winner, move_history, termination, output_b) # your output should look like this: """ #################### | 2 | | | | 1 | | | | #################### #################### 1 | 2 | |
def main(): # try: # sample_board = Board(RandomPlayer(), RandomPlayer()) # # setting up the board as though we've been playing # sample_board.move_count = 1 # sample_board.__board_state__ = [ # [0, 0, 0, 0, 0, 0, 0], # [0, 0, 0, 0, 0, 0, 0], # [0, 0, 0, 0, 0, 0, 0], # [0, 0, 0, 'Q', 0, 0, 0], # [0, 0, 0, 0, 0, 0, 0], # [0, 0, 0, 0, 0, 0, 0], # [0, 0, 0, 0, 0, 0, 0] # ] # sample_board.__last_queen_move__ = (3,3) # test = sample_board.get_legal_moves() # h = OpenMoveEvalFn() # print 'OpenMoveEvalFn Test: This board has a score of %s.' % (h.score(sample_board)) # except NotImplementedError: # print 'OpenMoveEvalFn Test: Not implemented' # except: # print 'OpenMoveEvalFn Test: ERROR OCCURRED' # print traceback.format_exc() # # # try: # """Example test to make sure # your minimax works, using the # #computer_player_moves.""" # # create dummy 5x5 board # # p1 = CustomPlayer() # p2 = CustomPlayer(search_depth=3) # #p2 = HumanPlayer() # b = Board(p1, p2, 5, 5) # b.__board_state__ = [ # [0, 0, 0, 0, 0], # [0, 0, 0, 0, 0], # [0, 0, 'Q', 0, 0], # [0, 0, 0, 0, 0], # [0, 0, 0, 0, 0] # ] # b.__last_queen_move__ = (2, 2) # # b.move_count = 1 # # output_b = b.copy() # winner, move_history, termination = b.play_isolation_name_changed() # print 'Minimax Test: Runs Successfully' # print winner # # Uncomment to see example game # # print game_as_text(winner, move_history, termination, output_b) # except NotImplementedError: # print 'Minimax Test: Not Implemented' # except: # print 'Minimax Test: ERROR OCCURRED' # print traceback.format_exc() # win = 0 lose = 0 for i in range(1, 101, 1): """Example test you can run to make sure your AI does better than random.""" try: r = CustomPlayer() h = RandomPlayer() game = Board(h, r, 7, 7) output_b = game.copy() winner, move_history, termination = game.play_isolation_name_changed() if 'CustomPlayer' in str(winner): print 'CustomPlayer Test: CustomPlayer Won' win += 1 else: print 'CustomPlayer Test: CustomPlayer Lost' lose += 1 # Uncomment to see game # print game_as_text(winner, move_history, termination, output_b) except NotImplementedError: print 'CustomPlayer Test: Not Implemented' except: print 'CustomPlayer Test: ERROR OCCURRED' print traceback.format_exc() print 'Win:', win, 'Lost:', lose
# (unlike .apply_move()). # new_game = game.forecast_move((1, 1)) # assert(new_game.to_string() != game.to_string()) # print("\nOld state:\n{}".format(game.to_string())) # print("\nNew state:\n{}".format(new_game.to_string())) # play the remainder of the game automatically -- outcome can be "illegal # move" or "timeout"; it should _always_ be "illegal move" in this example time_limit = 200 curr_time_millis = lambda: 1000 * timeit.default_timer() while True: legal_player_moves = game.get_legal_moves() game_copy = game.copy() move_start = curr_time_millis() time_left = lambda: time_limit - (curr_time_millis() - move_start) curr_move = game.active_player.get_move(game_copy, legal_player_moves, time_left) move_end = time_left() # print move_end if curr_move is None: curr_move = Board.NOT_MOVED print("move", curr_move) game.apply_move(curr_move)
def main(): try: sample_board = Board(RandomPlayer(), RandomPlayer()) # setting up the board as though we've been playing sample_board.move_count = 1 sample_board.__board_state__ = [ [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 'Q', 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0] ] sample_board.__last_queen_move__ = (3,3) test = sample_board.get_legal_moves() #h = OpenMoveEvalFn() h = CustomEvalFn() print 'OpenMoveEvalFn Test: This board has a score of %s.' % (h.score(sample_board)) except NotImplementedError: print 'OpenMoveEvalFn Test: Not implemented' except: print 'OpenMoveEvalFn Test: ERROR OCCURRED' print traceback.format_exc() try: """Example test to make sure your minimax works, using the #computer_player_moves.""" # create dummy 5x5 board p1 = CustomPlayer() p2 = CustomPlayer(search_depth=3) #p2 = HumanPlayer() b = Board(p1, p2, 5, 5) b.__board_state__ = [ [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 'Q', 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0] ] b.__last_queen_move__ = (2, 2) b.move_count = 1 output_b = b.copy() winner, move_history, termination = b.play_isolation_name_changed() print 'Minimax Test: Runs Successfully' print winner # Uncomment to see example game #print game_as_text(winner, move_history, termination, output_b) except NotImplementedError: print 'Minimax Test: Not Implemented' except: print 'Minimax Test: ERROR OCCURRED' print traceback.format_exc() """Example test you can run to make sure your AI does better than random.""" try: r = CustomPlayer_1(8) # h = RandomPlayer() h = CustomPlayer() #r = RandomPlayer() game = Board(r, h, 7, 7) output_b = game.copy() winner, move_history, termination = game.play_isolation_name_changed() if 'CustomPlayer' in str(winner): print 'CustomPlayer Test: CustomPlayer Won' else: print 'CustomPlayer Test: CustomPlayer Lost' # Uncomment to see game print game_as_text(winner, move_history, termination, output_b) except NotImplementedError: print 'CustomPlayer Test: Not Implemented' except: print 'CustomPlayer Test: ERROR OCCURRED' print traceback.format_exc()
"""Example test you can run to make sure your AI does better than random.""" from isolation import Board, game_as_text from test_players import RandomPlayer from player_submission import CustomPlayer if __name__ == "__main__": r = RandomPlayer() h = CustomPlayer() game = Board(h, r) output = game.copy() winner, move_history, termination = game.play_isolation(time_limit=500) print game_as_text(winner, move_history, termination, output)
TIME_LIMIT = 150 # number of milliseconds before timeout Agent = namedtuple("Agent", ["player", "name"]) Agent1 = Agent(AlphaBetaPlayer(score_fn=open_move_score), "MM_Open") #Agent1 = Agent(MinimaxPlayer(score_fn=open_move_score), "MM_Open") #Agent2 = Agent(RandomPlayer(), "Random") Agent2 = Agent(AlphaBetaPlayer(score_fn=improved_score), "AB_Improved") game = Board(Agent1.player, Agent2.player,9,9) #game._board_state = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 51] #game._board_state = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 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, 0, 0, 0, 0, 0, 0, 0, 24, 32] #game._board_state = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 51] game._board_state = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 47, 51] print(game.to_string()) legal_player_moves = game.get_legal_moves() legal_player_moves.sort() print("legal_player_moves:",legal_player_moves) move_history = [] time_limit = 150 time_millis = lambda: 1000 * timeit.default_timer() game_copy = game.copy() move_start = time_millis() # initialize starting point each time time_left = lambda : time_limit - (time_millis() - move_start) curr_move = game._active_player.get_move(game_copy, time_left) print("curr_move:",curr_move)
def main(): # print "" # try: # sample_board = Board(RandomPlayer(), RandomPlayer()) # # setting up the board as though we've been playing # sample_board.move_count = 2 # sample_board.__board_state__ = [ # ["Q1", " ", " ", " ", " ", " ", " "], # [" ", " ", " ", " ", " ", " ", " "], # [" ", " ", " ", " ", " ", " ", " "], # [" ", " ", " ", "Q2", " ", " ", " "], # [" ", " ", " ", " ", " ", " ", " "], # [" ", " ", " ", " ", " ", " ", " "], # [" ", " ", " ", " ", " ", " ", " "] # ] # sample_board.__last_queen_move__ = {sample_board.__queen_1__: (0, 0, False), \ # sample_board.__queen_2__: (3, 3, False)} # test = sample_board.get_legal_moves() # h = OpenMoveEvalFn() # print 'OpenMoveEvalFn Test: This board has a score of %s.' % (h.score(sample_board)) # except NotImplementedError: # print 'OpenMoveEvalFn Test: Not implemented' # except: # print 'OpenMoveEvalFn Test: ERROR OCCURRED' # print traceback.format_exc() # # print "" # try: # """Example test to make sure # your minimax works, using the # OpenMoveEvalFunction evaluation function. # This can be used for debugging your code # with different model Board states. # Especially important to check alphabeta # pruning""" # # create dummy 5x5 board # b = Board(RandomPlayer(), HumanPlayer(), 5, 5) # # b.__board_state__ = [ # [" ", " ", " ", " ", " "], # [" ", " ", " ", " ", " "], # [" ", " ", " ", "Q1", " "], # [" ", " ", " ", "Q2", " "], # [" ", " ", " ", " ", " "] # ] # b.__last_queen_move__[b.__queen_1__] = (2, 3, False) # b.__last_queen_move__[b.__queen_2__] = (3, 3, False) # b.move_count = 2 # # output_b = b.copy() # legal_moves = b.get_legal_moves() # winner, move_history, termination = b.play_isolation( # time_limit=100000, print_moves=True) # print 'Minimax Test: Runs Successfully' # # Uncomment to see example game # # insert in reverse order # # initial_turn = [(2, 3, False), (3, 3, False)] # # move_history.insert(0, initial_turn) # # print game_as_text(winner, move_history, termination, output_b) # except NotImplementedError: # print 'Minimax Test: Not Implemented' # except: # print 'Minimax Test: ERROR OCCURRED' # print traceback.format_exc() """Example test you can run to make sure your AI does better than random.""" cnt = 0 for i in range(0, 1): try: r = RandomPlayer() h = CustomPlayer(2) game = Board(r, h, 7, 7) output_b = game.copy() winner, move_history, termination = game.play_isolation( time_limit=1000, print_moves=True) if winner == 'CustomPlayer - Q2': cnt += 1 print "\n", winner, " has won. Reason: ", termination # Uncomment to see game # print game_as_text(winner, move_history, termination, output_b) except NotImplementedError: print 'CustomPlayer Test: Not Implemented' except: print 'CustomPlayer Test: ERROR OCCURRED' print traceback.format_exc() print "Win Rate ", float(cnt * 1.0 / 100.0)
def main(): """ print "" try: sample_board = Board(RandomPlayer(), RandomPlayer()) # setting up the board as though we've been playing sample_board.move_count = 2 sample_board.__board_state__ = [ ["Q1", " ", " ", " ", " ", " ", " "], [ " ", " ", " ", " ", " ", " ", " "], [ " ", " ", " ", " ", " ", " ", " "], [ " ", " ", " ","Q2", " ", " ", " "], [ " ", " ", " ", " ", " ", " ", " "], [ " ", " ", " ", " ", " ", " ", " "], [ " ", " ", " ", " ", " ", " ", " "] ] sample_board.__last_queen_move__ = {sample_board.__queen_1__: (0, 0, False), \ sample_board.__queen_2__: (3, 3, False)} test = sample_board.get_legal_moves() h = OpenMoveEvalFn() print 'OpenMoveEvalFn Test: This board has a score of %s.' % (h.score(sample_board)) except NotImplementedError: print 'OpenMoveEvalFn Test: Not implemented' except: print 'OpenMoveEvalFn Test: ERROR OCCURRED' print traceback.format_exc() """ print "" try: """Example test to make sure your minimax works, using the OpenMoveEvalFunction evaluation function. This can be used for debugging your code with different model Board states. Especially important to check alphabeta pruning""" # create dummy 5x5 board b = Board(RandomPlayer(), CustomPlayer(4), 5, 5) b.__board_state__ = [[" ", " ", " ", " ", " "], [" ", " ", " ", " ", " "], [" ", " ", " ", "Q1", " "], [" ", " ", " ", "Q2", " "], [" ", " ", " ", " ", " "]] b.__last_queen_move__[b.__queen_1__] = (2, 3, False) b.__last_queen_move__[b.__queen_2__] = (3, 3, False) b.move_count = 2 output_b = b.copy() legal_moves = b.get_legal_moves() winner, move_history, termination = b.play_isolation(time_limit=100000, print_moves=True) print 'Minimax Test: Runs Successfully' # Uncomment to see example game #insert in reverse order #initial_turn = [(2, 3, False), (3, 3, False)] #move_history.insert(0, initial_turn) #print game_as_text(winner, move_history, termination, output_b) except NotImplementedError: print 'Minimax Test: Not Implemented' except: print 'Minimax Test: ERROR OCCURRED' print traceback.format_exc() """Example test you can run to make sure your AI does better than random.""" print "" try: r = RandomPlayer() h = CustomPlayer() game = Board(r, h, 7, 7) output_b = game.copy() winner, move_history, termination = game.play_isolation( time_limit=1000, print_moves=True) print "\n", winner, " has won. Reason: ", termination # Uncomment to see game # print game_as_text(winner, move_history, termination, output_b) except NotImplementedError: print 'CustomPlayer Test: Not Implemented' except: print 'CustomPlayer Test: ERROR OCCURRED' print traceback.format_exc()
def main(): try: sample_board = Board(RandomPlayer(), RandomPlayer()) # setting up the board as though we've been playing sample_board.move_count = 4 sample_board.__board_state__ = [[11, 0, 0, 0, 21, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 22, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 12, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0]] sample_board.__last_queen_move__ = { sample_board.queen_11: (0, 0), sample_board.queen_12: (4, 5), sample_board.queen_21: (0, 4), sample_board.queen_22: (2, 2) } test = sample_board.get_legal_moves() h = OpenMoveEvalFn() print 'OpenMoveEvalFn Test: This board has a score of %s.' % ( h.score(sample_board)) except NotImplementedError: print 'OpenMoveEvalFn Test: Not implemented' except: print 'OpenMoveEvalFn Test: ERROR OCCURRED' print traceback.format_exc() try: """Example test to make sure your minimax works, using the OpenMoveEvalFunction evaluation function. This can be used for debugging your code with different model Board states. Especially important to check alphabeta pruning""" # create dummy 5x5 board p1 = RandomPlayer() p2 = HumanPlayer() b = Board(p1, p2, 5, 5) b.__board_state__ = [[0, 0, 0, 0, 0], [0, 0, 0, 22, 0], [0, 0, 0, 11, 0], [0, 0, 0, 21, 12], [0, 0, 0, 0, 0]] b.__last_queen_move__["queen11"] = (2, 3) b.__last_queen_move__["queen12"] = (3, 4) b.__last_queen_move__["queen21"] = (3, 3) b.__last_queen_move__["queen22"] = (1, 3) b.move_count = 4 output_b = b.copy() legal_moves = b.get_legal_moves() winner, move_history, termination = b.play_isolation() print 'Minimax Test: Runs Successfully' # Uncomment to see example game print game_as_text(winner, move_history, termination, output_b) except NotImplementedError: print 'Minimax Test: Not Implemented' except: print 'Minimax Test: ERROR OCCURRED' print traceback.format_exc() """Example test you can run to make sure your AI does better than random.""" try: r = RandomPlayer() h = CustomPlayer() game = Board(r, h, 7, 7) output_b = game.copy() winner, move_history, termination = game.play_isolation() print game_as_text(winner, move_history, termination, output_b) if 'CustomPlayer' in str(winner): print 'CustomPlayer Test: CustomPlayer Won' else: print 'CustomPlayer Test: CustomPlayer Lost' # Uncomment to see game # print game_as_text(winner, move_history, termination, output_b) except NotImplementedError: print 'CustomPlayer Test: Not Implemented' except: print 'CustomPlayer Test: ERROR OCCURRED' print traceback.format_exc()