agent.py
def exist(self, percept_stack):
        """
        Main agent loop that selects and action, acts, remembers
        what happen, learns, updates, saves the progress and
        decides if it should die
        """
        log.debug('entering main agent loop')
        while True:

            start = time.time()
            action_selected = self.select_action(percept_stack)
            new_percept_stack, reward = self.act_and_perceive(action_selected, percept_stack)
            log.debug("act and percieve took " + str(time.time() - start))

            start = time.time()
            self.remember((percept_stack, action_selected, reward, new_percept_stack))
            log.debug("remembering took " + str(time.time() - start))

            start = time.time()
            self.learn_maybe()
            log.debug("learning took " + str(time.time() - start))

            log.debug('updating the image stack')
            percept_stack = new_percept_stack
            self.step += 1

            start = time.time()
            if self.step % self.save_interval == 0:
                self.save_progress(percept_stack)
            log.debug("save progress took " + str(time.time() - start))

            timestep_info = "timestep", self.step, "epsilon", self.epsilon, \
                            "action_selected", action_selected, "reward", reward
            if reward != 0:
                log.info(timestep_info)
            else:
                log.debug(timestep_info)

            if self.environment.score_last_changed() and not self.train:
                best_of, matches_per_game = self.environment.first_to
                cpu_games, agent_games = self.environment.games
                cpu_score, agent_score = self.environment.score
                current_game = cpu_games + agent_games
                title = ' SCOREBOARD '

                log.info('=' * 20 + title + '=' * 20)
                log.info('best of ' + str(best_of) + ' games')
                log.info('each game goes to ' +
                         str(matches_per_game) +
                         ' points')
                log.info('-' * (40 + len(title)))
                log.info('game # ' + str(current_game) + ' score:')
                log.info('-' * (40 + len(title)))
                log.info('cpu ' + str(cpu_score))
                log.info('agent ' + str(agent_score))
                log.info('-' * (40 + len(title)))
                log.info('overall score:')
                log.info('-' * (40 + len(title)))
                log.info('cpu ' + str(cpu_games))
                log.info('agent ' + str(agent_games))
                log.info('=' * (40 + len(title)))

            if not self.train and self.environment.game_over():
                log.info('killing the agent. Train was ' +
                         str(self.train) +
                         ' and game over was ' +
                         str(self.environment.game_over()))
                cpu_games, agent_games = self.environment.games
                won = agent_games > cpu_games
                log.info(('agent won ' if won else 'cpu won ') +
                         '... final score ' + str(cpu_games) +
                         ' to ' + str(agent_games))
                break

        Main agent loop that selects and action, acts, remembers
        what happen, learns, updates, saves the progress and
        decides if it should die
        
Main agent loop that selects and action, acts, remembers
what happen, learns, updates, saves the progress and
decides if it should die
Main agent loop that selects and action acts remembers what happen learns updates saves the progress and decides if it should die
def exist(self, percept_stack):
        log.debug('entering main agent loop')
        while True:
            start = time.time()
            action_selected = self.select_action(percept_stack)
            new_percept_stack, reward = self.act_and_perceive(action_selected, percept_stack)
            log.debug("act and percieve took " + str(time.time() - start))
            start = time.time()
            self.remember((percept_stack, action_selected, reward, new_percept_stack))
            log.debug("remembering took " + str(time.time() - start))
            start = time.time()
            self.learn_maybe()
            log.debug("learning took " + str(time.time() - start))
            log.debug('updating the image stack')
            percept_stack = new_percept_stack
            self.step += 1
            start = time.time()
            if self.step % self.save_interval == 0:
                self.save_progress(percept_stack)
            log.debug("save progress took " + str(time.time() - start))
            timestep_info = "timestep", self.step, "epsilon", self.epsilon, \
                            "action_selected", action_selected, "reward", reward
            if reward != 0:
                log.info(timestep_info)
            else:
                log.debug(timestep_info)
            if self.environment.score_last_changed() and not self.train:
                best_of, matches_per_game = self.environment.first_to
                cpu_games, agent_games = self.environment.games
                cpu_score, agent_score = self.environment.score
                current_game = cpu_games + agent_games
                title = ' SCOREBOARD '
                log.info('=' * 20 + title + '=' * 20)
                log.info('best of ' + str(best_of) + ' games')
                log.info('each game goes to ' +
                         str(matches_per_game) +
                         ' points')
                log.info('-' * (40 + len(title)))
                log.info('game # ' + str(current_game) + ' score:')
                log.info('-' * (40 + len(title)))
                log.info('cpu ' + str(cpu_score))
                log.info('agent ' + str(agent_score))
                log.info('-' * (40 + len(title)))
                log.info('overall score:')
                log.info('-' * (40 + len(title)))
                log.info('cpu ' + str(cpu_games))
                log.info('agent ' + str(agent_games))
                log.info('=' * (40 + len(title)))
            if not self.train and self.environment.game_over():
                log.info('killing the agent. Train was ' +
                         str(self.train) +
                         ' and game over was ' +
                         str(self.environment.game_over()))
                cpu_games, agent_games = self.environment.games
                won = agent_games > cpu_games
                log.info(('agent won ' if won else 'cpu won ') +
                         '... final score ' + str(cpu_games) +
                         ' to ' + str(agent_games))
                break
def exist ( self , percept_stack ) : log . debug ( 'entering main agent loop' ) while True : start = time . time ( ) action_selected = self . select_action ( percept_stack ) new_percept_stack , reward = self . act_and_perceive ( action_selected , percept_stack ) log . debug ( "act and percieve took " + str ( time . time ( ) - start ) ) start = time . time ( ) self . remember ( ( percept_stack , action_selected , reward , new_percept_stack ) ) log . debug ( "remembering took " + str ( time . time ( ) - start ) ) start = time . time ( ) self . learn_maybe ( ) log . debug ( "learning took " + str ( time . time ( ) - start ) ) log . debug ( 'updating the image stack' ) percept_stack = new_percept_stack self . step += 1 start = time . time ( ) if self . step % self . save_interval == 0 : self . save_progress ( percept_stack ) log . debug ( "save progress took " + str ( time . time ( ) - start ) ) timestep_info = "timestep" , self . step , "epsilon" , self . epsilon , "action_selected" , action_selected , "reward" , reward if reward != 0 : log . info ( timestep_info ) else : log . debug ( timestep_info ) if self . environment . score_last_changed ( ) and not self . train : best_of , matches_per_game = self . environment . first_to cpu_games , agent_games = self . environment . games cpu_score , agent_score = self . environment . score current_game = cpu_games + agent_games title = ' SCOREBOARD ' log . info ( '=' * 20 + title + '=' * 20 ) log . info ( 'best of ' + str ( best_of ) + ' games' ) log . info ( 'each game goes to ' + str ( matches_per_game ) + ' points' ) log . info ( '-' * ( 40 + len ( title ) ) ) log . info ( 'game # ' + str ( current_game ) + ' score:' ) log . info ( '-' * ( 40 + len ( title ) ) ) log . info ( 'cpu ' + str ( cpu_score ) ) log . info ( 'agent ' + str ( agent_score ) ) log . info ( '-' * ( 40 + len ( title ) ) ) log . info ( 'overall score:' ) log . info ( '-' * ( 40 + len ( title ) ) ) log . info ( 'cpu ' + str ( cpu_games ) ) log . info ( 'agent ' + str ( agent_games ) ) log . info ( '=' * ( 40 + len ( title ) ) ) if not self . train and self . environment . game_over ( ) : log . info ( 'killing the agent. Train was ' + str ( self . train ) + ' and game over was ' + str ( self . environment . game_over ( ) ) ) cpu_games , agent_games = self . environment . games won = agent_games > cpu_games log . info ( ( 'agent won ' if won else 'cpu won ' ) + '... final score ' + str ( cpu_games ) + ' to ' + str ( agent_games ) ) break
Main agent loop that selects and action, acts, remembers
what happen, learns, updates, saves the progress and
decides if it should die
Main agent loop that selects and action acts remembers what happen learns updates saves the progress and decides if it should die
"""
        Main agent loop that selects and action, acts, remembers
        what happen, learns, updates, saves the progress and
        decides if it should die
        """
self
percept_stack