Google Research Football Documentation

repository·master·Indexed 25 days ago

https://github.com/google-research/football

An RL environment based on the open-source Gameplay Football game, designed for reinforcement learning research. It provides a GYM-style API for creating environments, training agents using PPO, and managing game states via get_state and set_state. The documentation covers installation across Linux, macOS, and Windows, manual play keyboard mappings, and the use of the gfootball package.

Tokens
7K
Snippets
18
Records
39
Agent score
84%

What's inside Google Research Football

  1. Compile Google Research Football on Linux

    master

    To build the environment on Linux, install the required system packages via apt-get, including cmake, build-essential, various sdl2 libraries, libboost-all-dev, and python3-pip.

    Steps:

    1. Install system dependencies using sudo apt-get install.
    2. Clone the repository.
    3. Create and activate a Python virtual environment.
    4. Upgrade pip, setuptools, and wheel, and install psutil.
    5. Run python3 -m pip install . to build the game environment.
    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 python3-pip
    
    python3 -m pip install --upgrade pip setuptools wheel
    python3 -m pip install psutil
    
    git clone https://github.com/google-research/football.git
    cd football
    
    python3 -m venv football-env
    source football-env/bin/activate
    
    python3 -m pip install --upgrade pip setuptools wheel
    python3 -m pip install psutil
    
    python3 -m pip install .
  2. Compile Google Research Football on macOS

    master

    To build the environment on macOS (Intel or Apple Silicon), use brew to install system dependencies including git, python3, cmake, sdl2, sdl2_image, sdl2_ttf, sdl2_gfx, boost, and boost-python3.

    Important Note on Python: It is highly recommended to use the Python distribution shipped with brew because boost-python3 is compiled against it. If your default python3 is not from Homebrew, create a virtual environment using $(brew --prefix python3)/bin/python3 -m venv football-env.

    Steps:

    1. Install prerequisites via brew.
    2. Clone the repository.
    3. Create and activate a virtual environment (using venv or conda).
    4. Upgrade pip, setuptools, and wheel, and install psutil.
    5. Run python3 -m pip install . to build the game environment.
    brew install git python3 cmake sdl2 sdl2_image sdl2_ttf sdl2_gfx boost boost-python3
    
    python3 -m pip install --upgrade pip setuptools wheel
    python3 -m pip install psutil
    
    git clone https://github.com/google-research/football.git
    cd football
    
    python3 -m venv football-env
    source football-env/bin/activate
    
    python3 -m pip install --upgrade pip setuptools wheel
    python3 -m pip install psutil
    
    python3 -m pip install .
  3. Obtain data for Imitation Learning

    master

    To perform Imitation Learning in Google Research Football, you can use game replays from the Kaggle competition. You can acquire this data in two ways:

    1. Collect replays manually: Use the Kaggle API to download replays from the Google Research Football competition on Kaggle.
    2. Use pre-processed datasets: Use existing datasets like the grf-replays-collection, which contains approximately 5,000 replays (primarily from top competition agents) that have been converted to a reduced size format.
  4. Train a policy controlling multiple players

    master

    To train a policy that controls multiple players, follow these two steps:

    1. Pass number_of_players_agent_controls to the create_environment function to define how many players the agent should control.
    2. When calling the .step() function, pass an array of actions (one action per player) instead of a single action.

    It is the responsibility of the caller to unpack or post-process these actions as needed. A reference implementation is available in examples/run_multiagent_rllib.py.

  5. Train agents using PPO

    master

    To run Reinforcement Learning training (specifically PPO), you must first install additional dependencies:

    1. Update PIP: python3 -m pip install --upgrade pip setuptools wheel
    2. TensorFlow (1.15): python3 -m pip install tensorflow==1.15.* (or tensorflow-gpu==1.15.* for GPU support)
    3. Sonnet and psutil: python3 -m pip install dm-sonnet==1.* psutil
    4. OpenAI Baselines: python3 -m pip install git+https://github.com/openai/baselines.git@master

    Running Experiments

    Run PPO on academy_empty_goal scenario:

    python3 -m gfootball.examples.run_ppo2 --level=academy_empty_goal_close

    Run PPO on academy_pass_and_shoot_with_keeper scenario:

    python3 -m gfootball.examples.run_ppo2 --level=academy_pass_and_shoot_with_keeper

    Run with rendering and episode saving:

    python3 -m gfootball.examples.run_ppo2 --dump_full_episodes=True --render=True
  6. Install Google Research Football

    master

    You can install Google Research Football on Linux, macOS, or Windows. The recommended way for Linux users is to use Docker to avoid package version conflicts. For direct installation, follow the platform-specific steps below.

    Linux

    Install system dependencies:

    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 python3-pip
    
    python3 -m pip install --upgrade pip setuptools psutil wheel

    macOS

    Install Homebrew, then install dependencies:

    brew install git python3 cmake sdl2 sdl2_image sdl2_ttf sdl2_gfx boost boost-python3
    
    python3 -m pip install --upgrade pip setuptools psutil wheel

    Windows

    Install Git and Python 3. Update pip using python (not python3) in the Command Line:

    python -m pip install --upgrade pip setuptools psutil wheel
  7. Build the Docker image

    master

    You can build the Docker image using two different base configurations depending on whether you require GPU support for TensorFlow training.

    ### Tensorflow without GPU-training support version
    ```bash
    docker build --build-arg DOCKER_BASE=ubuntu:20.04 . -t gfootball

    Tensorflow with GPU-training support version

    docker build --build-arg DOCKER_BASE=tensorflow/tensorflow:1.15.2-gpu-py3 . -t gfootball