original_docstring: Make an action. If `sleep` is given, the network will wait `sleep`
          seconds between each action.
  
          Args:
              action:
              frame_skip:
              sleep:
          
docstring: Make an action. If `sleep` is given, the network will wait `sleep`
  seconds between each action.
docstring_tokens: Make an action . If ` sleep ` is given the network will wait ` sleep ` seconds between each action .
code: def make_action(self, action, frame_skip=1, sleep=None):
          """Make an action. If `sleep` is given, the network will wait `sleep`
          seconds between each action.
  
          Args:
              action:
              frame_skip:
              sleep:
          """
          assert frame_skip >= 1
  
          # convert selected action to the ViZDoom action format
          action = self.action_builder.get_action(action)
  
          # select agent favorite weapon
          for weapon_name, weapon_ammo, weapon_id in WEAPONS_PREFERENCES:
              min_ammo = 40 if weapon_name == 'bfg9000' else 1
              if self.properties[weapon_name] > 0 and self.properties[weapon_ammo] >= min_ammo:
                  if self.properties['sel_weapon'] != weapon_id:
                      # action = ([False] * self.mapping['SELECT_WEAPON%i' % weapon_id]) + [True]
                      switch_action = ([False] * self.mapping['SELECT_WEAPON%i' % weapon_id]) + [True]
                      action = action + switch_action[len(action):]
                      self.log("Manual weapon change: %s -> %s" % (WEAPON_NAMES[self.properties['sel_weapon']], weapon_name))
                  break
  
          if action[self.mapping['MOVE_FORWARD']]:
              self.count_non_forward_actions = 0
          else:
              self.count_non_forward_actions += 1
  
          if action[self.mapping['TURN_LEFT']] or action[self.mapping['TURN_RIGHT']]:
              self.count_non_turn_actions = 0
          else:
              self.count_non_turn_actions += 1
  
          if self.manual_control and (self.count_non_forward_actions >= 30 or self.count_non_turn_actions >= 60):
              manual_action = [False] * len(action)
              manual_action[self.mapping['TURN_RIGHT']] = True
              manual_action[self.mapping['SPEED']] = True
              if self.count_non_forward_actions >= 30:
                  manual_action[self.mapping['MOVE_FORWARD']] = True
              manual_repeat = 40
              self.count_non_forward_actions = 0
              self.count_non_turn_actions = 0
          else:
              manual_action = None
  
          # if we are visualizing the experiment, show all the frames one by one
          if self.visible:
              if manual_action is not None:
                  logger.warning('Activated manual control')
                  for _ in range(manual_repeat):
                      self.game.make_action(manual_action)
              else:
                  for _ in range(frame_skip):
                      self.game.make_action(action)
                      # death or episode finished
                      if self.is_player_dead() or self.is_episode_finished():
                          break
                      # sleep for smooth visualization
                      if sleep is not None:
                          time.sleep(sleep)
          else:
              if manual_action is not None:
                  logger.warning('Activated manual control')
                  self.game.make_action(manual_action, manual_repeat)
              else:
                  self.game.make_action(action, frame_skip)
  
          # generate buffers
          game_state = self.game.get_state()
          if game_state is not None:
              self._screen_buffer = game_state.screen_buffer
              self._depth_buffer = game_state.depth_buffer
              self._labels_buffer = game_state.labels_buffer
              self._labels = game_state.labels
  
          # update game variables / statistics rewards
          self.update_game_variables()
          self.update_statistics_and_reward(action)
code_tokens: def make_action ( self , action , frame_skip = 1 , sleep = None ) : assert frame_skip >= 1 action = self . action_builder . get_action ( action ) for weapon_name , weapon_ammo , weapon_id in WEAPONS_PREFERENCES : min_ammo = 40 if weapon_name == 'bfg9000' else 1 if self . properties [ weapon_name ] > 0 and self . properties [ weapon_ammo ] >= min_ammo : if self . properties [ 'sel_weapon' ] != weapon_id : switch_action = ( [ False ] * self . mapping [ 'SELECT_WEAPON%i' % weapon_id ] ) + [ True ] action = action + switch_action [ len ( action ) : ] self . log ( "Manual weapon change: %s -> %s" % ( WEAPON_NAMES [ self . properties [ 'sel_weapon' ] ] , weapon_name ) ) break if action [ self . mapping [ 'MOVE_FORWARD' ] ] : self . count_non_forward_actions = 0 else : self . count_non_forward_actions += 1 if action [ self . mapping [ 'TURN_LEFT' ] ] or action [ self . mapping [ 'TURN_RIGHT' ] ] : self . count_non_turn_actions = 0 else : self . count_non_turn_actions += 1 if self . manual_control and ( self . count_non_forward_actions >= 30 or self . count_non_turn_actions >= 60 ) : manual_action = [ False ] * len ( action ) manual_action [ self . mapping [ 'TURN_RIGHT' ] ] = True manual_action [ self . mapping [ 'SPEED' ] ] = True if self . count_non_forward_actions >= 30 : manual_action [ self . mapping [ 'MOVE_FORWARD' ] ] = True manual_repeat = 40 self . count_non_forward_actions = 0 self . count_non_turn_actions = 0 else : manual_action = None if self . visible : if manual_action is not None : logger . warning ( 'Activated manual control' ) for _ in range ( manual_repeat ) : self . game . make_action ( manual_action ) else : for _ in range ( frame_skip ) : self . game . make_action ( action ) if self . is_player_dead ( ) or self . is_episode_finished ( ) : break if sleep is not None : time . sleep ( sleep ) else : if manual_action is not None : logger . warning ( 'Activated manual control' ) self . game . make_action ( manual_action , manual_repeat ) else : self . game . make_action ( action , frame_skip ) game_state = self . game . get_state ( ) if game_state is not None : self . _screen_buffer = game_state . screen_buffer self . _depth_buffer = game_state . depth_buffer self . _labels_buffer = game_state . labels_buffer self . _labels = game_state . labels self . update_game_variables ( ) self . update_statistics_and_reward ( action )
short_docstring: Make an action.
short_docstring_tokens: Make an action .
comment: """Make an action. If `sleep` is given, the network will wait `sleep`
          seconds between each action.
  
          Args:
              action:
              frame_skip:
              sleep:
          """$SEP$# convert selected action to the ViZDoom action format$SEP$# select agent favorite weapon$SEP$# action = ([False] * self.mapping['SELECT_WEAPON%i' % weapon_id]) + [True]$SEP$# if we are visualizing the experiment, show all the frames one by one$SEP$# death or episode finished$SEP$# sleep for smooth visualization$SEP$# generate buffers$SEP$# update game variables / statistics rewards