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.2

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.2
File Actions
codepraxis_football-0.2.2-cp312-abi3-win_amd64.whl CPython 3.12 abi3 Windows x86-64 Details for codepraxis_football-0.2.2-cp312-abi3-win_amd64.whl
codepraxis_football-0.2.2-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.2-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
codepraxis_football-0.2.2-cp312-abi3-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl CPython 3.12 abi3 Linux glibc 2.28+ ARM64, Linux glibc 2.27+ ARM64 Details for codepraxis_football-0.2.2-cp312-abi3-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
codepraxis_football-0.2.2-cp312-abi3-macosx_11_0_arm64.whl CPython 3.12 abi3 macOS 11.0+ ARM64 Details for codepraxis_football-0.2.2-cp312-abi3-macosx_11_0_arm64.whl
codepraxis_football-0.2.2-cp312-abi3-macosx_10_15_x86_64.whl CPython 3.12 abi3 macOS 10.15+ x86-64 Details for codepraxis_football-0.2.2-cp312-abi3-macosx_10_15_x86_64.whl

Total release size: 54.0 MB

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

Download URL codepraxis_football-0.2.2-cp312-abi3-win_amd64.whl
Size 10.6 MB
Tags CPython 3.12 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
0feff201310c1151c1ee3fc55735406b54cf4b66a7919a994b6e321bc6ae3f38
BLAKE2b-256 checksum
How to use checksums
57304d40b96788b4e667bdcbb2f5cd24a4ec1e8333f233364d52d8d34260b533
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.2-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL codepraxis_football-0.2.2-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
ce07506c78d03e61f4388d2154c50bc2bf82ceace7f6777f7aab6f80b1c9030b
BLAKE2b-256 checksum
How to use checksums
b9984582ed1d00b205f6f7b9cba791b5e7e259f5ef25b15e86f3d386c6b98c3e
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.2-cp312-abi3-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl

Download URL codepraxis_football-0.2.2-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
c8080542f79a63b05731d6310e2aea48dd7ac52b8600e38e2559dff6309ef1aa
BLAKE2b-256 checksum
How to use checksums
e3cdb35ce308c9290d7ea9e91637f62c785d4cafa75027c9adc533f1dd02aca3
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.2-cp312-abi3-macosx_11_0_arm64.whl

Download URL codepraxis_football-0.2.2-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
c1235658c0d1744688e2054a4494af539bea13bbd888f5f792a91616aaea400b
BLAKE2b-256 checksum
How to use checksums
81cc373a112b11fbc3c830b224475abd7009e84f30352b5c3b3327c1c8d9b682
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.2-cp312-abi3-macosx_10_15_x86_64.whl

Download URL codepraxis_football-0.2.2-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
59ac1561e7a1eea1f3b123f9d5bc39f17ea7d8c4aded2becd575ace032b823cc
BLAKE2b-256 checksum
How to use checksums
016b212cf615de90e5048aa37af7c3435a2153aea88074cb6d09e86ffeeb9803
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.2

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.2-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