original_docstring: Update statistics of the current game based on the previous and the
          current properties, and create a reward.
  
          Args:
              action:
          
docstring: Update statistics of the current game based on the previous and the
  current properties, and create a reward.
docstring_tokens: Update statistics of the current game based on the previous and the current properties and create a reward .
code: def update_statistics_and_reward(self, action):
          """Update statistics of the current game based on the previous and the
          current properties, and create a reward.
  
          Args:
              action:
          """
          stats = self.statistics[self.map_id]
  
          # reset reward
          self.reward_builder.reset()
  
          # we need to know the current and previous properties
          assert self.prev_properties is not None and self.properties is not None
  
          # distance
          moving_forward = action[self.mapping['MOVE_FORWARD']]
          turn_left = action[self.mapping['TURN_LEFT']]
          turn_right = action[self.mapping['TURN_RIGHT']]
          if moving_forward and not (turn_left or turn_right):
              diff_x = self.properties['position_x'] - self.prev_properties['position_x']
              diff_y = self.properties['position_y'] - self.prev_properties['position_y']
              distance = math.sqrt(diff_x ** 2 + diff_y ** 2)
              self.reward_builder.distance(distance)
  
          # kill
          d = self.properties['score'] - self.prev_properties['score']
          if d > 0:
              self.reward_builder.kill(d)
              stats['kills'] += d
              for _ in range(int(d)):
                  self.log('Kill')
  
          # death
          if self.game.is_player_dead():
              self.reward_builder.death()
              stats['deaths'] += 1
              self.log('Dead')
  
          # suicide
          if self.properties['frag_count'] < self.prev_properties['frag_count']:
              self.reward_builder.suicide()
              stats['suicides'] += 1
              self.log('Suicide')
  
          # found / lost health
          d = self.properties['health'] - self.prev_properties['health']
          if d != 0:
              if d > 0:
                  self.reward_builder.medikit(d)
                  stats['medikits'] += 1
              else:
                  self.reward_builder.injured(d)
              self.log('%s health (%i -> %i)' % (
                  'Found' if d > 0 else 'Lost',
                  self.prev_properties['health'],
                  self.properties['health'],
              ))
  
          # found / lost armor
          d = self.properties['armor'] - self.prev_properties['armor']
          if d != 0:
              if d > 0:
                  self.reward_builder.armor()
                  stats['armors'] += 1
              self.log('%s armor (%i -> %i)' % (
                  'Found' if d > 0 else 'Lost',
                  self.prev_properties['armor'],
                  self.properties['armor'],
              ))
  
          # change weapon
          if self.properties['sel_weapon'] != self.prev_properties['sel_weapon']:
              self.log('Switched weapon: %s -> %s' % (
                  WEAPON_NAMES[self.prev_properties['sel_weapon']],
                  WEAPON_NAMES[self.properties['sel_weapon']],
              ))
  
          # found weapon
          for i, weapon in enumerate(['pistol', 'shotgun', 'chaingun',
                                      'rocketlauncher', 'plasmarifle',
                                      'bfg9000']):
              if self.prev_properties[weapon] == self.properties[weapon]:
                  continue
              # assert(self.prev_properties[weapon] == 0 and  # TODO check
              #        self.properties[weapon] == 1), (weapon, self.prev_properties[weapon], self.properties[weapon])
              self.reward_builder.weapon()
              stats[weapon] += 1
              self.log('Found weapon: %s' % WEAPON_NAMES[i + 1])
  
          # found / lost ammo
          for ammo in ['bullets', 'shells', 'rockets', 'cells']:
              d = self.properties[ammo] - self.prev_properties[ammo]
              if d != 0:
                  if d > 0:
                      self.reward_builder.ammo()
                      stats[ammo] += 1
                  else:
                      self.reward_builder.use_ammo()
                  self.log('%s ammo: %s (%i -> %i)' % (
                      'Found' if d > 0 else 'Lost',
                      ammo,
                      self.prev_properties[ammo],
                      self.properties[ammo]
                  ))
code_tokens: def update_statistics_and_reward ( self , action ) : stats = self . statistics [ self . map_id ] self . reward_builder . reset ( ) assert self . prev_properties is not None and self . properties is not None moving_forward = action [ self . mapping [ 'MOVE_FORWARD' ] ] turn_left = action [ self . mapping [ 'TURN_LEFT' ] ] turn_right = action [ self . mapping [ 'TURN_RIGHT' ] ] if moving_forward and not ( turn_left or turn_right ) : diff_x = self . properties [ 'position_x' ] - self . prev_properties [ 'position_x' ] diff_y = self . properties [ 'position_y' ] - self . prev_properties [ 'position_y' ] distance = math . sqrt ( diff_x ** 2 + diff_y ** 2 ) self . reward_builder . distance ( distance ) d = self . properties [ 'score' ] - self . prev_properties [ 'score' ] if d > 0 : self . reward_builder . kill ( d ) stats [ 'kills' ] += d for _ in range ( int ( d ) ) : self . log ( 'Kill' ) if self . game . is_player_dead ( ) : self . reward_builder . death ( ) stats [ 'deaths' ] += 1 self . log ( 'Dead' ) if self . properties [ 'frag_count' ] < self . prev_properties [ 'frag_count' ] : self . reward_builder . suicide ( ) stats [ 'suicides' ] += 1 self . log ( 'Suicide' ) d = self . properties [ 'health' ] - self . prev_properties [ 'health' ] if d != 0 : if d > 0 : self . reward_builder . medikit ( d ) stats [ 'medikits' ] += 1 else : self . reward_builder . injured ( d ) self . log ( '%s health (%i -> %i)' % ( 'Found' if d > 0 else 'Lost' , self . prev_properties [ 'health' ] , self . properties [ 'health' ] , ) ) d = self . properties [ 'armor' ] - self . prev_properties [ 'armor' ] if d != 0 : if d > 0 : self . reward_builder . armor ( ) stats [ 'armors' ] += 1 self . log ( '%s armor (%i -> %i)' % ( 'Found' if d > 0 else 'Lost' , self . prev_properties [ 'armor' ] , self . properties [ 'armor' ] , ) ) if self . properties [ 'sel_weapon' ] != self . prev_properties [ 'sel_weapon' ] : self . log ( 'Switched weapon: %s -> %s' % ( WEAPON_NAMES [ self . prev_properties [ 'sel_weapon' ] ] , WEAPON_NAMES [ self . properties [ 'sel_weapon' ] ] , ) ) for i , weapon in enumerate ( [ 'pistol' , 'shotgun' , 'chaingun' , 'rocketlauncher' , 'plasmarifle' , 'bfg9000' ] ) : if self . prev_properties [ weapon ] == self . properties [ weapon ] : continue self . reward_builder . weapon ( ) stats [ weapon ] += 1 self . log ( 'Found weapon: %s' % WEAPON_NAMES [ i + 1 ] ) for ammo in [ 'bullets' , 'shells' , 'rockets' , 'cells' ] : d = self . properties [ ammo ] - self . prev_properties [ ammo ] if d != 0 : if d > 0 : self . reward_builder . ammo ( ) stats [ ammo ] += 1 else : self . reward_builder . use_ammo ( ) self . log ( '%s ammo: %s (%i -> %i)' % ( 'Found' if d > 0 else 'Lost' , ammo , self . prev_properties [ ammo ] , self . properties [ ammo ] ) )
short_docstring: Update statistics of the current game based on the previous and the
  current properties, and create a reward.
short_docstring_tokens: Update statistics of the current game based on the previous and the current properties and create a reward .
comment: """Update statistics of the current game based on the previous and the
          current properties, and create a reward.
  
          Args:
              action:
          """$SEP$# reset reward$SEP$# we need to know the current and previous properties$SEP$# distance$SEP$# kill$SEP$# death$SEP$# suicide$SEP$# found / lost health$SEP$# found / lost armor$SEP$# change weapon$SEP$# found weapon$SEP$# assert(self.prev_properties[weapon] == 0 and  # TODO check$SEP$#        self.properties[weapon] == 1), (weapon, self.prev_properties[weapon], self.properties[weapon])$SEP$# found / lost ammo