Пример #1
0
def main():
    game = goboard.GameState.new_game(BOARD_SIZE)
    max_depth = int(input('Depth search = '))
    max_width = int(input('Width search = '))
    step_change = int(
        input('Step where will be changed max_width and max_depth:'))

    agnt = my_predict.load_prediction_agent(h5py.File(path_model, 'r'))

    bot = minimax.AlphaBetaAgent(max_depth=max_depth,
                                 max_width=max_width,
                                 agnt=agnt,
                                 eval_fn=territory_diff)

    step = 0
    while not game.is_over():
        step += 1
        print_board(game.board)
        if game.next_player == gotypes.Player.black:
            human_move = input('-- ').upper()  # Nail
            print('Step = ', step)
            point = point_from_coords(human_move.strip())
            move = goboard.Move.play(point)
        else:
            if step < step_change:
                bot = minimax.AlphaBetaAgent(max_depth=3,
                                             max_width=3,
                                             agnt=agnt,
                                             eval_fn=capture_diff)
            else:
                bot = minimax.AlphaBetaAgent(max_depth=max_depth,
                                             max_width=max_width,
                                             agnt=agnt,
                                             eval_fn=territory_diff)
            time_begin = time.time()
            move = bot.select_move(game, agnt)
            time_select = time.time() - time_begin
            print('Time selection move = ', time_select)
            print('Step = ', step, ' Depth = ', max_depth, ' Width = ',
                  max_width)
            res, tb, tw = territory(game)
            print('Game current result = ', res)
        print_move(game.next_player, move)

        game = game.apply_move(move)
Пример #2
0
def main():
    game = goboard.GameState.new_game(BOARD_SIZE)
    bot = minimax.AlphaBetaAgent(3, capture_diff)

    while not game.is_over():
        print_board(game.board)
        if game.next_player == gotypes.Player.white:
            human_move = input('-- ')
            point = point_from_coords(human_move.strip())
            move = goboard.Move.play(point)
        else:
            move = bot.select_move(game)
        print_move(game.next_player, move)
        game = game.apply_move(move)
Пример #3
0
def main():
    print("******************************************************************")
    print("*                                                                *")
    print("*    <3 <3 <3 <3 <3     WELCOME TO GAME GO     <3 <3 <3 <3 <3    *")
    print("*                                                                *")
    print("******************************************************************")
    print("*                                                                *")
    print("*         1. Play game on terminal                               *")
    print("*                                                                *")
    print("*             a. Human vs Bot AlphaBeta on Board 9x9             *")
    print("*             b. Human vs Bot Depthprune on Board 9x9            *")
    print("*             c. Human vs Bot MCTS on Board 9x9                  *")
    print("*             d. Bot AlphaBeta vs Bot MCTS on Board 9x9          *")
    print("*                                                                *")
    print("*         2. Play game on web                                    *")
    print("*                                                                *")
    print("*             a. Human vs Bot MCTS on Board 9x9                  *")
    print("*             b. Human vs Bot DeepLearning on Board 19x19        *")
    print("*                                                                *")
    print("******************************************************************")
    print("                                                                  ")
    print("            *****************************************             ")
    print("                                                                  ")
    choices_A = int(input("                     Choose Terminal or Web: "))
    choices_B = input("                         Choose type bot: ")
    print("                                                                  ")
    print("            *****************************************             ")
    BOARD_SIZE = 9
    game = goboard.GameState.new_game(BOARD_SIZE)

    if choices_A == 1:
        if choices_B == 'a':
            bot = minimax.AlphaBetaAgent(4, capture_diff)
        if choices_B == 'b':
            bot = minimax.DepthPrunedAgent(4, capture_diff)
        if choices_B == 'c':
            bot = mcts.MCTSAgent(500, temperature=1.4)
        if choices_B == 'd':
            bots = {
                gotypes.Player.black: minimax.AlphaBetaAgent(4, capture_diff),
                gotypes.Player.white: mcts.MCTSAgent(500, temperature=1.4),
            }
            while not game.is_over():
                time.sleep(0.3)
                print_board(game.board)
                bot_move = bots[game.next_player].select_move(game)
                print_move(game.next_player, bot_move)
                game = game.apply_move(bot_move)

        if choices_B == 'a' or choices_B == 'b' or choices_B == 'c':
            while not game.is_over():
                print_board(game.board)
                if game.next_player == gotypes.Player.black:
                    human_move = input('-- ')
                    point = point_from_coords(human_move.strip())
                    move = goboard.Move.play(point)
                else:
                    move = bot.select_move(game)
                print_move(game.next_player, move)
                game = game.apply_move(move)
    else:
        if choices_B == 'a':
            bot = mcts.MCTSAgent(700, temperature=1.4)
            web_app = get_web_app({'mcts': bot})
            web_app.run()