How to use the gfootball.env.observation_rotation.flip_observation function in gfootball

To help you get started, we’ve selected a few gfootball examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github google-research / football / gfootball / env / football_env.py View on Github external
left_player_position, right_player_position):
    """Converts generic observations returned by the environment to
       the player specific observations.

    Args:
      original: original observations from the environment.
      player: player for which to generate observations.
      left_player_position: index into observation corresponding to the left
          player.
      right_player_position: index into observation corresponding to the right
          player.
    """
    observations = []
    for is_left in [True, False]:
      adopted = original if is_left or player.can_play_right(
      ) else observation_rotation.flip_observation(original, self._config)
      prefix = 'left' if is_left or not player.can_play_right() else 'right'
      position = left_player_position if is_left else right_player_position
      for x in range(player.num_controlled_left_players() if is_left
                     else player.num_controlled_right_players()):
        o = {}
        for v in constants.EXPOSED_OBSERVATIONS:
          o[v] = copy.deepcopy(adopted[v])
        assert (len(adopted[prefix + '_agent_controlled_player']) == len(
            adopted[prefix + '_agent_sticky_actions']))
        o['designated'] = adopted[prefix + '_team_designated_player']
        if position + x >= len(adopted[prefix + '_agent_controlled_player']):
          o['active'] = -1
          o['sticky_actions'] = []
        else:
          o['active'] = (
              adopted[prefix + '_agent_controlled_player'][position + x])