How to use the gfootball.env.football_action_set 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 / players / gamepad.py View on Github external
"""Player with actions coming from gamepad."""

from absl import logging
import pygame

from gfootball.env import controller_base
from gfootball.env import football_action_set
from gfootball.env import event_queue

BUTTON_TO_ACTIONS = {
    0: [football_action_set.action_short_pass,
        football_action_set.action_pressure],
    1: [football_action_set.action_shot,
        football_action_set.action_team_pressure],
    2: [football_action_set.action_high_pass,
        football_action_set.action_sliding],
    3: [football_action_set.action_long_pass,
        football_action_set.action_keeper_rush],
    4: [football_action_set.action_switch],
    5: [football_action_set.action_dribble],
}


class Player(controller_base.Controller):
  """Player with actions coming from gamepad."""

  def __init__(self, player_config, env_config):
    controller_base.Controller.__init__(self, player_config, env_config)
    self._can_play_right = True
    pygame.init()
    self._index = player_config['player_gamepad']
    event_queue.add_controller('gamepad', self._index)
github google-research / football / gfootball / env / players / bot.py View on Github external
def _get_action(self):
    """Returns action to perform for the current observations."""
    active = self._observation['left_team'][self._observation['active']]
    # Corner etc. - just pass the ball
    if self._observation['game_mode'] != 0:
      return football_action_set.action_long_pass

    if self._observation['ball_owned_team'] == 1:
      if self._last_action == football_action_set.action_pressure:
        return football_action_set.action_sprint
      self._pressure_enabled = True
      return football_action_set.action_pressure

    if self._pressure_enabled:
      self._pressure_enabled = False
      return football_action_set.action_release_pressure
    target_x = 0.85

    if (self._shoot_distance >
        np.linalg.norm(self._observation['ball'][:2] - [target_x, 0])):
      return football_action_set.action_shot
github google-research / football / gfootball / env / players / bot.py View on Github external
def _get_action(self):
    """Returns action to perform for the current observations."""
    active = self._observation['left_team'][self._observation['active']]
    # Corner etc. - just pass the ball
    if self._observation['game_mode'] != 0:
      return football_action_set.action_long_pass

    if self._observation['ball_owned_team'] == 1:
      if self._last_action == football_action_set.action_pressure:
        return football_action_set.action_sprint
      self._pressure_enabled = True
      return football_action_set.action_pressure

    if self._pressure_enabled:
      self._pressure_enabled = False
      return football_action_set.action_release_pressure
    target_x = 0.85

    if (self._shoot_distance >
        np.linalg.norm(self._observation['ball'][:2] - [target_x, 0])):
      return football_action_set.action_shot

    move_target = [target_x, 0]
    # Compute run direction.
    move_action = self._direction_action(move_target - active)

    closest_front_opponent = self._closest_front_opponent(active, move_target)
    if closest_front_opponent is not None:
      dist_front_opp = self._object_distance(active, closest_front_opponent)
    else:
      dist_front_opp = 2.0
github google-research / football / gfootball / env / football_env_wrapper.py View on Github external
def reset(self):
    """Reset environment for a new episode using a given config."""
    self._episode_start = timeit.default_timer()
    self._action_set = football_action_set.get_action_set(self._config)
    self._trace = observation_processor.ObservationProcessor(self._config)
    self._cumulative_reward = 0
    self._step_count = 0
    self._env.reset(self._trace)
    self._env_state = 'game_started'
github google-research / football / gfootball / env / observation_rotation.py View on Github external
def flip_single_action(action, config):
  """Actions corresponding to the field rotated by 180 degrees."""
  action = football_action_set.named_action_from_action_set(
      football_action_set.get_action_set(config), action)
  if action == football_action_set.action_left:
    return football_action_set.action_right
  if action == football_action_set.action_top_left:
    return football_action_set.action_bottom_right
  if action == football_action_set.action_top:
    return football_action_set.action_bottom
  if action == football_action_set.action_top_right:
    return football_action_set.action_bottom_left
  if action == football_action_set.action_right:
    return football_action_set.action_left
  if action == football_action_set.action_bottom_right:
    return football_action_set.action_top_left
  if action == football_action_set.action_bottom:
    return football_action_set.action_top
  if action == football_action_set.action_bottom_left:
    return football_action_set.action_top_right
  return action
github google-research / football / gfootball / env / controller_base.py View on Github external
self._last_action = football_action_set.action_idle
    self._check_action(football_action_set.action_long_pass,
                       active_actions)
    self._check_action(football_action_set.action_high_pass,
                       active_actions)
    self._check_action(football_action_set.action_short_pass,
                       active_actions)
    self._check_action(football_action_set.action_shot, active_actions)
    self._check_action(football_action_set.action_keeper_rush,
                       active_actions)
    self._check_action(football_action_set.action_sliding, active_actions)
    self._check_action(football_action_set.action_pressure,
                       active_actions)
    self._check_action(football_action_set.action_team_pressure,
                       active_actions)
    self._check_action(football_action_set.action_sprint, active_actions)
    self._check_action(football_action_set.action_dribble, active_actions)
    return self._last_action
github google-research / football / gfootball / env / remote_football_env.py View on Github external
def __init__(self, username, token, model_name='', track='default',
               include_rendering=False):
    self._config = FakeConfig(
        config.track_to_num_controlled_players.get(track, 1))
    self._num_actions = len(football_action_set.action_set_dict['default'])
    self._track = track
    self._include_rendering = include_rendering

    self._username = username
    self._token = token
    self._model_name = model_name

    self._game_id = None
    self._channel = None

    self._update_master()
github google-research / football / gfootball / env / observation_rotation.py View on Github external
def flip_single_action(action, config):
  """Actions corresponding to the field rotated by 180 degrees."""
  action = football_action_set.named_action_from_action_set(
      football_action_set.get_action_set(config), action)
  if action == football_action_set.action_left:
    return football_action_set.action_right
  if action == football_action_set.action_top_left:
    return football_action_set.action_bottom_right
  if action == football_action_set.action_top:
    return football_action_set.action_bottom
  if action == football_action_set.action_top_right:
    return football_action_set.action_bottom_left
  if action == football_action_set.action_right:
    return football_action_set.action_left
  if action == football_action_set.action_bottom_right:
    return football_action_set.action_top_left
  if action == football_action_set.action_bottom:
    return football_action_set.action_top
  if action == football_action_set.action_bottom_left:
    return football_action_set.action_top_right
  return action