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.3.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.3.0
File Actions
codepraxis_football-0.3.0-cp312-abi3-win_amd64.whl CPython 3.12 abi3 Windows x86-64 Details for codepraxis_football-0.3.0-cp312-abi3-win_amd64.whl
codepraxis_football-0.3.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.3.0-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
codepraxis_football-0.3.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.3.0-cp312-abi3-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
codepraxis_football-0.3.0-cp312-abi3-macosx_11_0_arm64.whl CPython 3.12 abi3 macOS 11.0+ ARM64 Details for codepraxis_football-0.3.0-cp312-abi3-macosx_11_0_arm64.whl
codepraxis_football-0.3.0-cp312-abi3-macosx_10_15_x86_64.whl CPython 3.12 abi3 macOS 10.15+ x86-64 Details for codepraxis_football-0.3.0-cp312-abi3-macosx_10_15_x86_64.whl

Total release size: 54.1 MB

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

Download URL codepraxis_football-0.3.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
50f35c939779e44df376e7580a167a5b7afa21f38767aa3682552c1d8d6696c6
BLAKE2b-256 checksum
How to use checksums
28f07c19ae4e2626d790b17e022fd2983986ba8318d89e112dc70782b7b97d69
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.3.0-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL codepraxis_football-0.3.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
0a77da9bb0415062e6c068019d69bed4cddce775128e1e07665b56d4fc6f53ed
BLAKE2b-256 checksum
How to use checksums
ec58ea0448a84f1a38aedd6d30107107d80fdb1c084a43e7dc0a1f941cd80fb5
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.3.0-cp312-abi3-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl

Download URL codepraxis_football-0.3.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
569dd28a782514348f1da49931b1f202f8568f4839972cc39981d4cae4cdbe47
BLAKE2b-256 checksum
How to use checksums
520895e6f86cce4fc8bff1e752e5e9fa93bdd193a1134a4893ca09fc3c152f47
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.3.0-cp312-abi3-macosx_11_0_arm64.whl

Download URL codepraxis_football-0.3.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
a09b39a0bc5a2f133c8685159e8039c1f031e485584b7ef94f76f331853cdd9c
BLAKE2b-256 checksum
How to use checksums
3cf6a16dddefb50ab886034926e649dc6f24c003c59f2862e9496eb87bad9d73
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.3.0-cp312-abi3-macosx_10_15_x86_64.whl

Download URL codepraxis_football-0.3.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
c544b908e991e4b3c2ddc35600373a0ee25727d52e3057466074f794bfa18508
BLAKE2b-256 checksum
How to use checksums
66cb87475e3fee63b910bcd50f4b84a5cd8fb6b2cc583ed58b0e2e38d26eede8
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.3.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.3.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