def rollout(self,start_node): if(start_node.terminal == True): if(start_node.winner == start_node.colour): return 1 elif(start_node.winner == -start_node.colour): return -1 else: return 0 else: # if last nodes player could not move need to cheack if following board state is terminal because game object would not catch it. if(start_node.moved == False): child_node = Node(start_node.board_state,start_node,-start_node.colour) if(child_node.terminal == True): if(child_node.winner == start_node.colour): return 1 elif(child_node.winner == -start_node.colour): return -1 else: return 0 else: #game will start with black to move --> simulate already one move if white is next to move if(start_node.colour == -1): name_player1 = 'opponent' name_player2 = 'self' if(start_node.moved == False): board_state = start_node.board_state else: board_state = random.choice(start_node.playing_player.possible_moves) else: board_state = start_node.board_state name_player2 = 'opponent' name_player1 = 'self' #initialise game between two Random player random_game = game.Game('GAMBLER',name_player1,'GAMBLER',name_player2,False) random_game.game_board = board_state random_game.run_game() if(random_game.winner == 'self'): return 1 elif(random_game.winner == 'opponent'): return -1 else: return 0
type_player2 = 'ALPHA_BETA' name_player1 = 'StaticBoard4' name_player2 = 'AlphaBeta4' f = open(f'{name_player1}_{name_player2}_{num_games}.txt', 'w') f.write(f'{num_games} games {name_player1} against {name_player2} for {name_player1}: black and {name_player2}: white.\n') f.write('"In first two columns winner gets 1 looser 0"\n') f.write('\n') f.write(f'{name_player1}_Winning,{name_player2}_Winning,Discs_{name_player1},Discs_{name_player2}\n') player_timer1 = playertimer.PlayerTimer(name_player1,name_player2,2 * num_games) player_timer2 = playertimer.PlayerTimer(name_player2,name_player1,2 * num_games) for x in range(num_games): game1 = game.Game(type_player1,name_player1,type_player2,name_player2,False) player_timer1.start_game() player_timer2.start_game() game1.run_game_timed(player_timer1,player_timer2) player_timer1.stop_game() player_timer2.stop_game() if(game1.winner == name_player1): f.write(f'1,0,{game1.num_discs_player1},{game1.num_discs_player2}\n') elif(game1.winner == name_player2): f.write(f'0,1,{game1.num_discs_player1},{game1.num_discs_player2}\n') else: f.write(f'0,0,{game1.num_discs_player1},{game1.num_discs_player2}\n') f.close() f = open(f'{name_player2}_{name_player1}_{num_games}.txt', 'w')
import othello_game.game as game f = open('Negamax4_Roxanne_10.txt', 'w') f.write( '"10 games Negamax agains Roxanne for Negamax: black and Roxanne: white."\n' ) f.write('"In first two columns winner gets 1 looser 0"\n') f.write('\n') f.write('Negamax_Winning, Roxanne_Winning, Disks_Negamax, Disks_Roxanne\n') for x in range(10): game1 = game.Game('NEGAMAX', 'Negamax', 'ROXANNE', 'Roxanne', False) game1.run_game() if (game1.winner == 'Roxanne'): f.write( f'0, 1, {game1.num_disks_player1}, {game1.num_disks_player2} \n') elif (game1.winner == 'Negamax'): f.write( f'1, 0, {game1.num_disks_player1}, {game1.num_disks_player2} \n') else: f.write( f'0, 0, {game1.num_disks_player1}, {game1.num_disks_player2} \n') f.close() f = open('Roxanne_Negamax4_10.txt', 'w') f.write( '"10 games Roxanne against Negamax for Roxanne: black and Negamax: white."\n' ) f.write('"In first two columns winner gets 1 looser 0"\n') f.write('\n')
import othello_game.game as game game1 = game.Game('STATIC_BOARD', 'StaticBoard', 'ALPHA_BETA', 'AlphaBeta', True) game1.run_game() print(f'Winner: {game1.winner}') print( f'Number of Disks: {game1.name_player1} : {game1.num_discs_player1}, {game1.name_player2} : {game1.num_discs_player2}' )