def worker(args, pid): board_size = args.board_size rounds = args.rounds max_moves = args.max_moves temperature = args.temperature for i in range(args.num_games): print('Process %d: Generating game %d/%d...' % (pid, i + 1, args.num_games)) game = goboard.GameState.new_game(board_size) bot = mcts.MCTSAgent(rounds, temperature) num_moves = 0 sgfgame = sgf.Sgf_game(board_size) # recorder sgf_info = adaptor.DokiGo_to_SGF() # adaptor while not game.is_over(): # print_board(game.board) move = bot.select_move(game) # print_move(game.next_player, move) node = sgfgame.extend_main_sequence() sgf_info.set_move(game.next_player, move) # recorder get info node.set_move(sgf_info.move_color, sgf_info.move_coordinates) # set node game = game.apply_move(move) num_moves += 1 if num_moves > max_moves: break sgf_info.set_game_result(game, sgfgame) # set game result with open(f"./selfplay_data/process{pid}_game{i}_rounds{rounds}.sgf", "wb") as f: # write into a file f.write(sgfgame.serialise())
def main(): board_size = 9 game = goboard.GameState.new_game(board_size) #bot = RandomBot() #bot = MCTSAgent(50,0.8) model, encoder = load_nn_model( "dokigo/DL_policy_prediction_MCTS/mcts_r50k.h5") bot = DeepLearningAgent(model, encoder) human_player = random.choice(list(base.Player)) print("Game Start! You will play: %s and AI will play: %s" % (human_player.name, human_player.other.name)) sgfgame = sgf.Sgf_game(board_size) # recorder sgf_info = adaptor.DokiGo_to_SGF() # adaptor while not game.is_over(): print(chr(27) + "[2J") print_board(game.board) if game.next_player == human_player: while True: human_move = input('-- ') if human_move == 'pass': move = goboard.Move.pass_turn() break elif human_move == 'resign': move = goboard.Move.resign() break else: point = point_from_coords(human_move.replace(' ', '')) move = goboard.Move.play(point) if game.board.is_on_grid( move.point) and game.is_valid_move(move): break print("This is not a value move!") else: move = bot.select_move(game) print_move(game.next_player, move) game = game.apply_move(move) node = sgfgame.extend_main_sequence() sgf_info.set_move(game.next_player, move) # recorder get info node.set_move(sgf_info.move_color, sgf_info.move_coordinates) # set node sgf_info.set_game_result(game, sgfgame) # set game result with open(f"game_human_vs_bot.sgf", "wb") as f: # write into a file f.write(sgfgame.serialise())
def main(): board_size = 9 total_games = 1 strong_bot_wins = 0 for m in range(total_games): game = goboard.GameState.new_game(board_size) bot_1 = RandomBot() bot_2 = MCTSAgent(100, 1.5) bot_1_color = random.choice(list(base.Player)) bot_2_color = bot_1_color.other sgfgame = sgf.Sgf_game(board_size) #recorder sgf_info = adaptor.DokiGo_to_SGF() #adaptor while not game.is_over(): # print(chr(27) + "[2J") # print_board(game.board) node = sgfgame.extend_main_sequence() if game.next_player == bot_1_color: move = bot_1.select_move(game) else: move = bot_2.select_move(game) #print_move(game.next_player, move) print("we are in game #:", m + 1) print("The advanced algorithm win #", strong_bot_wins) sgf_info.set_move(game.next_player, move) #recorder get info node.set_move(sgf_info.move_color, sgf_info.move_coordinates) #set node game = game.apply_move(move) if game.winner() == bot_2_color: strong_bot_wins += 1 sgf_info.set_game_result(game, sgfgame) #set game result with open(f"game{m}.sgf", "wb") as f: #write into a file f.write(sgfgame.serialise()) print("The winning rate is %.3f" % (strong_bot_wins / total_games))