# pdb.set_trace() #################################################################################### print('Start Learning!') ### 게임을 하면서, 학습을 하면서, policy를 업데이트 ########## #################################################################################### load_level = 2 angle_action_idx = 0 angle_action = valid_angles[angle_action_idx] taptime_action_idx = 0 taptime_action = valid_taptimes[angle_action_idx] i_episode = 0 loss = None # 수정: 여기서 하는게 맞나... Level_selection안에 넣어놨었는데, 여기를 들어가지 않고 실행되는 경우도 있었음 while True: game_state = comm.comm_get_state(s, silent=False) dqn_utils.clear_screenshot(SCR_PATH + "/") if game_state == 'UNKNOWN': print("########################################################") print("Unknown state") pass elif game_state == 'MAIN_MENU': print("########################################################") print("Main menu state") pass elif game_state == 'EPISODE_MENU': print("########################################################") print("Episode menu state") pass elif game_state == 'LEVEL_SELECTION':
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