Esempio n. 1
0
        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')
                        print(predicted_action)

            # Player 2
            else:
                predicted_action, temp_children, temp_moves = tree_search_2.search(
Esempio n. 2
0
    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]) + ',' +
                          str(predicted_action[3]) + ')')

        # Player 2
        else:
            print_board(game.state)
            selected_move = human.get_move(game, chain=False)
            game.play_action(selected_move)
            print('Human moved:', end="\t")