Skip to main content

CodePraxis Football

Write a Python agent that plays football. Test it on your laptop, watch it play, record videos, and score it the same way the judges do.

Install

pip install codepraxis-football        # Python 3.12 or newer; Mac, Linux, Windows
codepraxis-football doctor             # checks the engine, rendering and video
codepraxis-football init my-agent      # sample agent + this guide + a practice level
cd my-agent

On a Linux server or a minimal Linux install, the game needs the system OpenGL libraries: sudo apt install libgl1 libegl1 (desktops already have them). No GPU is needed.

Try it

codepraxis-football play shoot_keeper                    # play it yourself with the keyboard
codepraxis-football watch agent.py shoot_keeper          # watch your agent in a window
codepraxis-football eval agent.py shoot_keeper           # official score: 100 seeded episodes
codepraxis-football video agent.py shoot_keeper -o a.mp4 # record without a window
codepraxis-football watch-match agent.py random match_5v5 # two agents live: yellow vs blue
codepraxis-football match agent.py other.py match_5v5    # same, no window, JSON result
codepraxis-football levels                               # every level

The window and videos hold the picture for a moment after goals, cards and set pieces. Add --fast to skip that. Training and eval never pause. The 3D view (window, video --view 3d) runs extra engine code that changes how a match plays out, so the same seed can end differently there than in eval. video --view topdown shows exactly what eval scored.

Keyboard: arrows move, hold e sprint, hold c dribble, s short pass, a high pass, w long pass, d shoot, x slide tackle, Esc quit.

Write an agent

An agent is a file with one function. It gets what its player sees and returns one action:

from codepraxis_football import Action

def agent(obs):
    me = obs['left_team'][obs['active']]
    if me[0] > 0.7:
        return Action.SHOT
    return Action.RIGHT

Agents that need memory can use a class instead:

class Agent:
    def reset(self):          # start of every episode
        self.steps = 0
    def act(self, obs):
        self.steps += 1
        return Action.RIGHT

Optional settings at the top of the file:

Setting Default Meaning
OBSERVATION 'raw' 'raw' (dict), 'vector' (115 numbers), 'minimap' (72x96x4), 'pixels' (72x96x3, slow)
PLAYERS 1 How many of our players you control. With more than 1, obs is a list and you return a list

The pitch

x runs from -1 (our goal) to 1 (the goal you attack). y runs from -0.42 (top) to 0.42 (bottom). You always attack to the right, also when the judges play your agent as the other team.

Raw observation fields

Field Meaning
ball [x, y, z] ball position (z = height)
ball_direction [x, y, z] ball movement per step
ball_owned_team -1 nobody, 0 us, 1 them
ball_owned_player index of the player with the ball
left_team, right_team [x, y] of every player (left = us)
left_team_direction, right_team_direction movement per step of every player
left_team_roles, right_team_roles 0 GK, 1 CB, 2 LB, 3 RB, 4 DM, 5 CM, 6 LM, 7 RM, 8 AM, 9 CF
left_team_tired_factor, right_team_tired_factor 0 fresh to 1 exhausted
left_team_yellow_card, left_team_active (and right) cards; active False = sent off
active index (in left_team) of the player you control
sticky_actions 10 flags: 8 directions, sprint, dribble (on until released)
score [ours, theirs]
steps_left steps until the episode ends
game_mode 0 normal, 1 kick-off, 2 goal kick, 3 free kick, 4 corner, 5 throw-in, 6 penalty

Actions

# Action # Action
0 IDLE 10 HIGH_PASS
1-8 LEFT, TOP_LEFT, TOP, TOP_RIGHT, RIGHT, BOTTOM_RIGHT, BOTTOM, BOTTOM_LEFT 11 SHORT_PASS
9 LONG_PASS 12 SHOT
13 SPRINT 14 RELEASE_DIRECTION
15 RELEASE_SPRINT 16 SLIDING
17 DRIBBLE 18 RELEASE_DRIBBLE

Directions, sprint and dribble stay on until released. Passes and shots go the way the player faces.

Use it from Python (training)

import codepraxis_football as cpf

env = cpf.make('shoot_keeper', observation='vector')    # Gymnasium API
obs, info = env.reset(seed=0)
obs, reward, terminated, truncated, info = env.step(cpf.Action.SHOT)

reward is +1 for our goal and -1 for theirs. With no window the game runs at several hundred steps per second per CPU core; run one environment per core to train faster:

import gymnasium as gym

def make_env():
    return cpf.make('shoot_keeper', observation='vector')

if __name__ == '__main__':
    envs = gym.vector.AsyncVectorEnv([make_env] * 4)   # 4 processes
    obs, info = envs.reset(seed=[0, 1, 2, 3])

On a 2024 laptop, 4 environments run ~1,500 steps/s: a million training steps in about 11 minutes.

Reinforcement learning

Any library that speaks Gymnasium works. With Stable-Baselines3 (pip install stable-baselines3):

from stable_baselines3 import PPO
from stable_baselines3.common.vec_env import SubprocVecEnv, VecMonitor
import codepraxis_football as cpf

def make_env():
    return cpf.make('shoot_keeper', observation='vector', reward='checkpoints')

if __name__ == '__main__':
    envs = VecMonitor(SubprocVecEnv([make_env] * 4))
    model = PPO('MlpPolicy', envs, n_steps=512, batch_size=512, gamma=0.993)
    model.learn(total_timesteps=2_000_000)
    model.save('model')

reward='checkpoints' adds small rewards for carrying the ball towards the goal, so learning starts long before the first goal. Use the saved model as an agent:

import os
from stable_baselines3 import PPO
OBSERVATION = 'vector'
model = PPO.load(os.path.join(os.path.dirname(__file__), 'model.zip'))  # next to agent.py

def agent(obs):
    return int(model.predict(obs, deterministic=True)[0])

Scoring

eval runs your agent for 100 episodes with fixed seeds and prints JSON: goal_rate (episodes where you scored), avg_steps_to_goal, wins/draws/losses, timeouts and errors. A step slower than 50 ms counts as IDLE. If your agent raises an error, that episode scores nothing and the rest still run. The judges use the same command with seeds you haven't seen.

Make your own practice level

See my_level.py from init. Use a level file anywhere a level name goes: codepraxis-football watch agent.py my_level.py.

Metadata

Release files for codepraxis-football 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for codepraxis-football 0.2.0
File Actions
codepraxis_football-0.2.0-cp312-abi3-win_amd64.whl CPython 3.12 abi3 Windows x86-64 Details for codepraxis_football-0.2.0-cp312-abi3-win_amd64.whl
codepraxis_football-0.2.0-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 abi3 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details for codepraxis_football-0.2.0-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
codepraxis_football-0.2.0-cp312-abi3-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl CPython 3.12 abi3 Linux glibc 2.27+ ARM64, Linux glibc 2.28+ ARM64 Details for codepraxis_football-0.2.0-cp312-abi3-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
codepraxis_football-0.2.0-cp312-abi3-macosx_11_0_arm64.whl CPython 3.12 abi3 macOS 11.0+ ARM64 Details for codepraxis_football-0.2.0-cp312-abi3-macosx_11_0_arm64.whl
codepraxis_football-0.2.0-cp312-abi3-macosx_10_15_x86_64.whl CPython 3.12 abi3 macOS 10.15+ x86-64 Details for codepraxis_football-0.2.0-cp312-abi3-macosx_10_15_x86_64.whl

Total release size: 54.0 MB

Release files / codepraxis_football-0.2.0-cp312-abi3-win_amd64.whl

Download URL codepraxis_football-0.2.0-cp312-abi3-win_amd64.whl
Size 10.6 MB
Tags CPython 3.12 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
023fcac09f20d541e1e1407cca673a87dc4e1d01bf8fc2c0cb4a912914633559
BLAKE2b-256 checksum
How to use checksums
d9c8fa593f59fb9ad76499be04d1bde833f10d7b4092f4e61316157f834dbda5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

Release files / codepraxis_football-0.2.0-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL codepraxis_football-0.2.0-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 11.3 MB
Tags CPython 3.12 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
e4c955c3343a3afad48c67ffdd7cd71bbd3b2f535583c6397ed6265c9718ae62
BLAKE2b-256 checksum
How to use checksums
eb6b7a21f3af3f626ee3e7e85d47b23fd3de62b23a553f6b7790b28b562d7632
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

Release files / codepraxis_football-0.2.0-cp312-abi3-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl

Download URL codepraxis_football-0.2.0-cp312-abi3-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Size 11.1 MB
Tags CPython 3.12 Linux glibc 2.27+ ARM64 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
834495f8c01d22a3f012304a796831ed42fc1a8c0d37345bdbf3cadc01af64a4
BLAKE2b-256 checksum
How to use checksums
8b0ffea269f6c6b2471b4488d7182f788783c08c8ad26e04fe3501a995932caf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

Release files / codepraxis_football-0.2.0-cp312-abi3-macosx_11_0_arm64.whl

Download URL codepraxis_football-0.2.0-cp312-abi3-macosx_11_0_arm64.whl
Size 10.5 MB
Tags CPython 3.12 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
a935f4ed04e04d631125690a4b155dab55cb451efe23c5d6d7abe860968a0820
BLAKE2b-256 checksum
How to use checksums
4328e7291dbc59022fe8e5bb9c39f810dbab35d2063d3877c140fe01a1baad38
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

Release files / codepraxis_football-0.2.0-cp312-abi3-macosx_10_15_x86_64.whl

Download URL codepraxis_football-0.2.0-cp312-abi3-macosx_10_15_x86_64.whl
Size 10.6 MB
Tags CPython 3.12 abi3 macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
29ced84573863b3f8c07543e6cb7b220ff19b770b3486f30dbccd241d27f0ca8
BLAKE2b-256 checksum
How to use checksums
5d988ed16159c81cfda910244fd402c38b29e954c1662be052858ddc493e300f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

Security for codepraxis-football 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 5 files in this release have been uploaded with provenance metadata.

Select from 5 files

Attestation for codepraxis_football-0.2.0-cp312-abi3-win_amd64.whl

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page