boing-gym
Boing! — the Pong of Code the Classics, Volume 1 (Raspberry Pi Press) — as a Gymnasium environment, so that a program can play it, and a program can present it to a person and log what happens, frame by frame.
import gymnasium as gym
import boing_gym
env = gym.make("Boing-v0")
obs, info = env.reset(seed=0)
obs, reward, terminated, truncated, info = env.step(boing_gym.UP)
frame = env.render() # (480, 800, 3) uint8, the book's picture
python -m boing_gym plays it in a window (arrows or A/Z; --two-players
adds K/M), menu and all.
Installing
pip install boing-gym
Depends on gymnasium, numpy and pygame; the sprites and sounds are in
the package. Nothing needs a display: pygame draws on offscreen surfaces, and
the tests run under SDL_VIDEODRIVER=dummy SDL_AUDIODRIVER=dummy.
git clone https://github.com/chrplr/boing-gym
pip install -e "boing-gym[dev]" && pytest
A release is cut by bumping __version__ in src/boing_gym/__init__.py to
the tag's number and pushing the tag vX.Y.Z; the release workflow refuses a
tag that does not match, and publishes the package to PyPI.
The environment
src/boing_gym/game.py is boing.py from the book with Pygame Zero taken
out: the same constants, the same ball, bats and computer player, one
Game.update() per frame of the book's 60 Hz loop. boing.py itself sits at
the root of the repository, unchanged, as the reference.
| id | step budget | for |
|---|---|---|
Boing-v0 |
6000 frames (100 s) | agents |
BoingHuman-v0 |
none | a person: a match ends when it is won |
Both are boing_gym.env.BoingEnv. One step is one frame: the action moves
the left bat, the right bat is the book's computer player.
- Actions:
Discrete(3)—STAY(0),UP(1),DOWN(2), each a frame of the bat's movement (6 px).DEFAULT_KEYSis the book's player-1 keyboard by key name:UP/DOWNarrows, orA/Z. - Observations:
obs_mode="state"(default) is a(9,)float32 vector: ball x, y, direction dx, dy (a unit vector), speed (px per frame, 5 at a serve and +1 per hit), left bat y, right bat y, left score, right score.obs_mode="rgb"is the(480, 800, 3)picture. - Reward: +1 for a point won, −1 for a point lost, 0 otherwise. The
episode terminates when a score passes 9. Truncation is the
TimeLimitwrapper's (Boing-v0only). - Rendering:
render_mode="rgb_array"(the default) returns the frame the book draws — table, bats, ball, impact sprites, scores, the flash on a conceded point. Nothing else is drawn: the book's menu, attract mode and "game over" screens are the caller's business. - Sound:
audio=Truedecodes the book's effects once and mixes the ones each frame triggers into a(rate/60, 2)int16 block,get_audio_buffer()after each step, atget_audio_sampling_rate()Hz (44100 unlesspygame.mixerwas already initialised at another rate). For a harness with its own output stream;python -m boing_gymplays them through the mixer. - Reproducibility: the only random draw is the computer's aiming offset
after each hit (and the choice among sound variants), from a
random.Randomseeded byreset(seed=). A seed and a sequence of actions determine a match — and its soundtrack — completely. infoeach step:event("hit","wall","point","serve", joined by+when several fall in one frame,""otherwise),ball_x,ball_y,ball_dx,ball_dy,ball_speed,bat0_y,bat1_y,score0,score1,scorer(0 or 1 on a point, else −1),n_frames,n_hits,game_over.
Credits and license
The game — code, sprites and sounds — is from Code the Classics, Volume 1 by Eben Upton, Sean M. Tracey and others, published by Raspberry Pi Press, whose books are released under CC BY-NC-SA 3.0. This package is a derived work under the same license.
Metadata
Release files for boing-gym 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| boing_gym-0.1.0.tar.gz | 3.4 MB | With provenance | Details for boing_gym-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| boing_gym-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for boing_gym-0.1.0-py3-none-any.whl |
Total release size: 4.3 MB
Release files / boing_gym-0.1.0.tar.gz
| Download URL | boing_gym-0.1.0.tar.gz |
|---|---|
| Size | 3.4 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6af137fcc46b9349560568d037b256f2d6a978a101eb64bfc40cd5c0af99fdcb
|
|
BLAKE2b-256 checksum How to use checksums |
d1371ca3c360ead7121c3486ed26d5c01c8129618f9f32749c6f203a0300c901
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 20, 2026.
Transparency logRelease files / boing_gym-0.1.0-py3-none-any.whl
| Download URL | boing_gym-0.1.0-py3-none-any.whl |
|---|---|
| Size | 966.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b6228d6008a522842852d55831ca548d2d2a6d44b30faa842328e8ceafdc3aab
|
|
BLAKE2b-256 checksum How to use checksums |
3386abcd8f823279a0190c415cf47d54abcabd83dceae28eae726103b6a2e23c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 20, 2026.
Transparency logSecurity for boing-gym 0.1.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
Both files in this release have been uploaded with provenance metadata.
Attestation for boing_gym-0.1.0.tar.gz
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 Sep 20, 2026.
Transparency logA 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.