How google-research/football works
Main Components
• Python RL Environment (gfootball package):
– Contains modules for environment setup, configuration, and game scenarios (see gfootball/env, gfootball/scenarios, gfootball/examples).
– Hosts integrations for different types of players (keyboard, external agents, etc.) and the CLI entry point (play_game.py).
– Provides API documentation and training scripts to interact with RL frameworks.
• Game Engine (C++ Implementation):
– Found under third_party/gfootball_engine.
– Implements the fast simulation of game logic, physics, and rendering support.
– Built using CMake and integrated through build scripts in gfootball (e.g., build_game_engine.sh / .bat).
• Evaluation Server:
– Located in gfootball/eval_server.
– Implements communication via protocol buffers (proto files) to support evaluation routines and remote client interactions.
• CI/CD & Deployment:
– Dockerfile and Docker related scripts (Dockerfile, run_docker_test.sh, .github/workflows) support containerized builds and tests.
– GitHub Actions workflows manage builds for macOS and wheel publishing.
Relationships and Interactions
• The Python environment acts as a wrapper around the C++ game engine:
– When a user invokes the game (via gfootball.play_game), the Python layer initializes the environment, loads the appropriate scenario, and then communicates with the compiled game engine (built from the third_party/gfootball_engine code).
– The engine provides state updates and simulation steps back into the environment that delivers observations to agents and converts their actions into game events.
• The Evaluation Server operates as an auxiliary component:
– It exposes an API via gRPC (as shown by the proto definitions) to allow remote evaluation or testing with external client agents.
• The training scripts and examples (in gfootball/examples) serve as a bridge:
– They integrate with popular RL frameworks (TensorFlow 1.15, OpenAI Baselines) and use the Python environment to receive observations and provide actions in training loops.
• CI/CD components (Docker & GitHub workflows) support cross-platform builds and ensure that tests run (including building the C++ engine) are passed before publishing packages or deploying demos.
Important Architectural Patterns & Design Principles
• Separation of Concerns:
– The game engine (C++) focuses solely on speed and simulation fidelity, while the Python layer provides the interface for training agents and handling high-level API calls.
• Modular Design:
– The environment’s design is split into submodules (env, players, scenarios, examples) that can be developed, extended, or replaced individually.
• Integration via Wrappers:
– Python wrappers encapsulate the compiled C++ code, enabling seamless use in RL pipelines.
• Standardized Communication:
– Use of protocol buffers (in eval_server) and clear API boundaries (documentation in gfootball/doc) promote maintainability and extensibility.
Relevant Technologies, Frameworks, or Libraries
• For the Python Layer:
– Python3, TensorFlow 1.15, OpenAI Baselines, Gym-like interfaces.
• For the Game Engine (C++):
– CMake build system, SDL2 for rendering/input support, and various custom libraries/modules organized within third_party/gfootball_engine.
• For Deployment & CI:
– Docker for containerized builds, GitHub Actions for automated CI/CD.