Пример #1
0
            print("=============== Level", current_level, "===============")

            for t in itertools.count():  # 이 에피소드가 끝날때까지

                shot_dir = os.path.join(
                    episode_dir, "level%d_shot%d_%s" %
                    (current_level, t, time.strftime('%Y%m%d_%H%M%S')))
                if not os.path.exists(shot_dir):
                    os.mkdir(shot_dir)
                while True:
                    is_zoomed_out = comm.comm_fully_zoomout(s)
                    if is_zoomed_out == 1:
                        break
                screenshot_path = shot_dir + "/s_%d.png" % t
                state_raw_img = comm.comm_do_screenshot(s, screenshot_path)
                save_path = screenshot_path + "_seg.png"
                state_img = wrapper.save_seg(screenshot_path, save_path)
                # state = dqn_utils.get_feature_4096(model=vgg16, img_path=save_path) # 수정: 이 함수 안에서 크기 조절하는게 좋을 듯
                # pdb.set_trace()

                print('Choose action from given Q network model')

                # # Epsilon for this time step
                # epsilon = epsilons[min(total_t, epsilon_decay_steps-1)]
                #
                # # Add epsilon to Tensorboard
                # # episode_summary = tf.Summary()
                # # episode_summary.value.add(simple_value=epsilon, tag="epsilon")
                # # q_estimator.summary_writer.add_summary(episode_summary, total_t)
                #
Пример #2
0
def get_score_after_shot(current_dir,
                         parser,
                         comm_socket,
                         start_score,
                         fast=False):
    """
    Get score after shot.

    Args:
      parser : Wrapper object
      comm_socket : server-client socket
      start_score : score before shooting
    Return:
      reward (last_score - start_score)
      new_score (last_score)
      save_path (next state raw image path. WON or LOST should be captured at terminal state.)
      state (PLAYING or WON or LOST)
    """

    end_image = None
    save_path = None
    screenshot = None
    last_score = start_score
    sleepcount = 0
    if fast:
        full_sleep = 6
    else:
        full_sleep = 15

    # Shooting is done. Check the score
    while True:
        # check the status of the screenshot
        save_path = "%s/screenshots/screenshot_%d.png" % (
            current_dir, int(time.time() * 1000))
        screenshot = comm.comm_do_screenshot(comm_socket, save_path=save_path)
        if comm.comm_get_state(comm_socket) == 'WON':
            score = parser.get_score_end_game(save_path)
        else:
            score = parser.get_score_in_game(save_path)

        # if the new score is less than the last score, something went wrong, just return the last status
        # pdb.set_trace()

        if (score > last_score):
            end_image = screenshot
            last_score = score
            sleepcount = 0

        # PLAYING / WON / LOST
        elif last_score == score:
            if (comm.comm_get_state(comm_socket) == 'LOST'):
                save_path = "%s/screenshots/screenshot_%d.png" % (
                    current_dir, int(time.time() * 1000))
                end_image = comm.comm_do_screenshot(comm_socket,
                                                    save_path=save_path)
                break
            if comm.comm_get_state(comm_socket) == 'WON':
                time.sleep(1)
                save_path = "%s/screenshots/screenshot_%d.png" % (
                    current_dir, int(time.time() * 1000))
                end_image = comm.comm_do_screenshot(comm_socket,
                                                    save_path=save_path)
                last_score = parser.get_score_end_game(save_path)
                break
            time.sleep(1)
            sleepcount += 1
            if sleepcount >= full_sleep:
                save_path = "%s/screenshots/screenshot_%d.png" % (
                    current_dir, int(time.time() * 1000))
                end_image = comm.comm_do_screenshot(comm_socket,
                                                    save_path=save_path)
                print('over slept')
                sys.stdout.flush()
                break

        else:  # last_score > score:
            if comm.comm_get_state(
                    comm_socket) == 'WON' or comm.comm_get_state(
                        comm_socket) == 'LOST':
                save_path = "%s/screenshots/screenshot_%d.png" % (
                    current_dir, int(time.time() * 1000))
                end_image = comm.comm_do_screenshot(comm_socket,
                                                    save_path=save_path)
                if comm.comm_get_state(comm_socket) == 'WON':
                    last_score = parser.get_score_end_game(save_path)
                else:
                    break
            else:
                print("something wrong...")

        # if the no change count and passed time are enough, return.
    state = comm.comm_get_state(comm_socket)
    return last_score - start_score, last_score, save_path, state