google-research / football
- воскресенье, 9 июня 2019 г. в 00:17:50
Python
This repository contains a RL environment based on open-source game Gameplay Football. It was created by Google Brain team for research purposes.
This is not an official Google product.
We'd like to thank Bastiaan Konings Schuiling, who authored and opensourced the original version of this game.
For more information, please look at our paper (github).
Currently we're supporting only Linux and Python3. You can either install the code from github (newest version) or from pypi (stable version).
Install required apt packages with
sudo apt-get install git cmake build-essential libgl1-mesa-dev libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev libsdl2-gfx-dev libboost-all-dev libdirectfb-dev libst-dev mesa-utils xvfb x11vnc libsqlite3-dev glee-dev libsdl-sge-dev python3-pip
Install gfootball python package from pypi:
- Use `pip3 install gfootball[tf_cpu] --process-dependency-links` if you want to use CPU version of TensorFlow.
- Use `pip3 install gfootball[tf_gpu] --process-dependency-links` if you want to use GPU version of TensorFlow.
- This command can run for couple of minutes, as it compiles the C++ environment in the background.
- `git clone https://github.com/google-research/football.git`
- `cd football`
- Use `pip3 install .[tf_cpu] --process-dependency-links` if you want to use CPU version of TensorFlow.
- Use `pip3 install .[tf_gpu] --process-dependency-links` if you want to use GPU version of TensorFlow.
- This command can run for couple of minutes, as it compiles the C++ environment in the background.
academy_empty_goal scenario, run
python3 -m gfootball.examples.run_ppo2 --level=academy_empty_goal_closeacademy_pass_and_shoot_with_keeper scenario, run
python3 -m gfootball.examples.run_ppo2 --level=academy_pass_and_shoot_with_keeperIn order to train with nice replays being saved, run
python3 -m gfootball.examples.run_ppo2 --dump_full_episodes=True --render=True
Run python3 -m gfootball.play_game. By default it starts the
base scenario and the home player is controlled by the keyboard. Different types
of players are suported (game pad, external bots, agents...). For possible
options run python3 -m gfootball.play_game -helpfull.
Please note that playing the game is implemented through environment, so human-controlled players use the same interface as the agents. One important fact is that there is a single action per 100 ms reported to the environment, which might cause lag effect when playing.
You can implement your own player by adding its implementation to the env/players directory (no other changes are needed). Have a look at existing players code for example implementation.
The game defines following keyboard mapping:
ARROW UP - run to the top.ARROW DOWN - run to the bottom.ARROW LEFT - run to the left.ARROW RIGHT - run to the right.S - short pass in attack mode, pressure in the defence mode.A - high pass in attack mode, sliding in the defence mode.D - shot in the attack mode, team pressure in the defence mode.W - long pass in the attack mode, goal keeper pressure in the defence mode.Q - switch active player on defence mode.C - dribble in the attack mode.E - sprint.docker build --build-arg DOCKER_BASE=ubuntu:18.04 --build-arg DEVICE=cpu . -t gfootballdocker run -it gfootball bashdocker build --build-arg DOCKER_BASE=tensorflow/tensorflow:1.12.0-gpu-py3 --build-arg DEVICE=gpu . -t gfootballnvidia-docker run -it gfootball bashAfter entering the image, you can run sample training with python3 -m gfootball.examples.run_ppo2.
Unfortunately, rendering is not supported inside the docker.
Environment exposes following observations:
ball - [x, y, z] position of the ball.ball_direction - [x, y, z] ball movement vector.ball_rotation - [x, y, z] rotation angles in radians.ball_owned_team - {-1, 0, 1}, -1 = ball not owned, 0 = home team, 1 = away team.ball_owned_player - {0..N-1} integer denoting index of the player owning the ball.home_team - N-elements vector with [x, y] positions of players.home_team_direction - N-elements vector with [x, y] movement vectors of players.home_team_tired_factor - N-elements vector of floats in the range {0..1}. 0 means player is not tired at all.home_team_yellow_card - N-elements vector of integers denoting number of yellow cards a given player has (0 or 1).home_team_active - N-elements vector of Bools denoting whether a given player is playing the game (False means player got a red card).home_team_roles - N-elements vector denoting roles of players. The meaning is:
0 = e_PlayerRole_GK - goalkeeper,1 = e_PlayerRole_CB - centre back,2 = e_PlayerRole_LB - left back,3 = e_PlayerRole_RB - right back,4 = e_PlayerRole_DM - defence midfield,5 = e_PlayerRole_CM - central midfield,6 = e_PlayerRole_LM - left midfield,7 = e_PlayerRole_RM - right midfield,8 = e_PlayerRole_AM - attack midfield,9 = e_PlayerRole_CF - central front,away_team - same as for home team.away_team_direction - same as for home team.away_team_tired_factor - same as for home team.away_team_yellow_card - same as for home team.away_team_active - same as for home team.away_team_roles - same as for home team.active - {0..N-1} integer denoting index of the controlled player.sticky_actions - 13-elements vector of 0s or 1s denoting whether corresponding actions are active:
game_leftgame_top_leftgame_topgame_top_rightgame_rightgame_bottom_rightgame_bottomgame_bottom_leftgame_keeper_rushgame_pressuregame_team_pressuregame_sprintgame_dribblescore - pair of integers denoting number of goals for home and away teams, respectively.steps_left - how many steps are left till the end of the match.game_mode - current game mode, one of:
0 = e_GameMode_Normal1 = e_GameMode_KickOff2 = e_GameMode_GoalKick3 = e_GameMode_FreeKick4 = e_GameMode_Corner5 = e_GameMode_ThrowIn6 = e_GameMode_Penaltyframe - three 1280x720 vectors of RGB pixels representing rendered
screen. It is only exposed when rendering is enabled (render flag).Where N is the number of players on the team.
X coordinates are int the range [-1, 1].
Y coordinates are int the range [-0.42, 0.42].
Speed vectors represent change in the possition of the object within a single
step.
We provide two sets of scenarios/levels:
Football Benchmarks
Football Academy - with a total of 11 scenarios
You can add your own scenarios by adding a new file to the gfootball/scenarios/
directory. Have a look at existing scenarios for example.
GFootball environment supports recording of scenarios for later watching or
analysis. Each trace dump consists of a picked episode trace (observations,
reward, additional debug info) and optionally an AVI file with rendered episode.
Picked episode trace can be played back later on using replay.py script.
By default trace dumps are disabled to not occupy disk space. They
are controlled by the following set of flags:
dump_full_episodes - should trace for each entire episode be recorded.dump_scores - should sampled traces for scores be recorded.tracesdir - directory in which trace dumps are saved.write_video - should video be recorded together with the trace.
If rendering is disabled (render config flag), video contains a simple
episode animation.