def agent_start(self, observation): screen = observation.intArray[128:] screen = np.reshape(screen, (210, -1)) maze = detect_maze(screen) self.image = pacman_image(maze) return_action = Action() action = randrange(self.numActions) return_action.intArray = [action] self.lastAction = copy.deepcopy(return_action) self.lastObservation = copy.deepcopy(observation) return return_action
pygame.init() ale.setBool('sound', False) # Sound doesn't work on OSX elif sys.platform.startswith('linux'): ale.setBool('sound', True) ale.setBool('display_screen', True) # Load the ROM file ale.loadROM(sys.argv[1]) # Get the list of legal actions legal_actions = ale.getLegalActionSet() # Play 10 episodes screen = np.reshape(ale.getScreen(), (210, -1)) maze = detect_maze(screen) image = pacman_image(maze) # print_maze(maze) for episode in xrange(1): total_reward = 0 step = 1 while not ale.game_over(): # if step == 500: screen = np.reshape(ale.getScreen(), (210, -1)) if step % 3 == 0: image.new_image(screen) a = legal_actions[randrange(len(legal_actions))] step += 1 # Apply an action and get the resulting reward reward = ale.act(a); total_reward += reward