Esempio n. 1
0
        store = Store()
        game = Game()

        # Starting 1 Self-play Game
        step = 1
        draw = False
        while game.check_game_over() == 0:
            clone = game.clone()
            # Player 1
            if step % 2 != 0:
                predicted_action, temp_children, temp_moves = tree_search_1.search(
                    game.clone())
                temp_policy = get_tree_policy(temp_children, temp_moves)
                store.update_store([game.clone().state, temp_policy, 0],
                                   player1=True)
                game.play_action(predicted_action)
                print('P1 Non Chain -> ', end='\t')
                print(predicted_action)
                if clone.if_attack_move(predicted_action):
                    while game.attack_move_available(
                            game.remove_except_current(predicted_action)):
                        predicted_action, temp_children, temp_moves = tree_search_1.search(
                            game.clone(),
                            chain_move=True,
                            action=predicted_action)
                        temp_policy = get_tree_policy(temp_children,
                                                      temp_moves)
                        store.update_store(
                            [game.clone().state, temp_policy, 0], player1=True)
                        game.play_action(predicted_action)
                        print('P1 Chain -> ', end='\t')
Esempio n. 2
0
    net = Residual()
    net.load_model('models/model11')
    tree_search_1 = MCTS(net, Node())
    human = Human()
    game = Game()
    print('Game has started !')
    print_board(game.state)
    step = 1

    while game.check_game_over() == 0:
        clone = game.clone()
        # Player 1
        if step % 2 != 0:
            predicted_action, temp_children, temp_moves = tree_search_1.search(
                game.clone())
            game.play_action(predicted_action)
            print('Computer moved:', end='\t')
            print('(' + str(predicted_action[0]) + ',' +
                  str(predicted_action[1]) + ') -> (' +
                  str(predicted_action[2]) + ',' + str(predicted_action[3]) +
                  ')')
            if clone.if_attack_move(predicted_action):
                while game.attack_move_available(
                        game.remove_except_current(predicted_action)):
                    predicted_action, temp_children, temp_moves = tree_search_1.search(
                        game.clone(), chain_move=True, action=predicted_action)
                    game.play_action(predicted_action)
                    print('Computer moved:', end='\t')
                    print('(' + str(predicted_action[0]) + ',' +
                          str(predicted_action[1]) + ') -> (' +
                          str(predicted_action[2]) + ',' +