A ROM-free Zelda-like Gymnasium environment built on Pygame.
Project description
gym-zelda-pygame
A Gymnasium environment that wraps the Clear Code Pygame “Zelda” game into a ROM-free, modern RL playground. It exposes a pixel-observation interface, discrete actions, sensible rewards, and familiar wrappers (skip-frames, gray-scale resize to 84×84, frame-stack, normalize, channel-first) so you can train DQN/PPO/IMPALA-style agents without touching emulators or legacy Gym.
Motivation
I recently finished a playthrough of The Legend of Zelda: Breath of the Wild and wanted to experiment with applying reinforcement learning to a Zelda-style world. Most existing environments either:
- rely on ROMs/emulators, or
- are tangled up with deprecated
gym+ NumPy compatibility issues.
Environment Details
Spaces
-
Action Space:
Discrete(8)0) no-op- move up
- move down
- move left
- move right
- attack
- magic
- menu
-
Observation Space:
Box(low=0, high=255, shape=(720, 1280, 3), dtype=uint8)by default
(Typically wrap this 84×84 grayscale and stack frames for learning)
Rendering
render_mode="human": Pygame window (60 FPS throttle)render_mode="rgb_array": returns the current frame as a numpy array- Headless safety: when not using
"human", SDL dummy drivers are used automatically.
Episode Termination
- Episode ends when:
- Player health ≤ 0, or
- All enemies defeated
Reward
Default (configurable) reward shaping in ZeldaEnv:
- Small step penalty:
-0.001per step (encourage efficiency) - Health changes: penalty for loss, small reward for gain
- Experience gain: small positive reward
- Enemy defeats: large positive reward (
+10.0per enemy) - Death penalty:
-100.0
You can pass a custom reward function via custom_reward_fn:
def my_reward_fn(current_state, previous_state, episode_steps):
# current_state: dict with keys shown below
# previous_state: same keys for previous step
# return float
...
env = ZeldaEnv(render_mode="rgb_array", custom_reward_fn=my_reward_fn)
Info Dict
Each step() returns an info dict with:
{
'episode_steps': int,
'player_health': int,
'player_exp': int,
'enemy_count': int,
'player_pos': (x: int, y: int),
}
Credit
- Game code adapted from Clear Code’s Zelda tutorial: clear-code-projects/Zelda
- Graphics and audio assets courtesy of Pixel-boy/AAA under CC0: Ninja Adventure asset pack
Respect the original projects’ licenses and assets. This environment is an RL wrapper around their codebase to support education.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gym_zelda_pygame-0.1.8.tar.gz.
File metadata
- Download URL: gym_zelda_pygame-0.1.8.tar.gz
- Upload date:
- Size: 2.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe964460b76cac4d7bf04c74a005aa2ea50a42322a69c9b4843f4bd069155eae
|
|
| MD5 |
bede9d83ffd4a01f4236c3891a0f7135
|
|
| BLAKE2b-256 |
d0db4b85416fdb94989600e78013911cdd938964739ea7640141001a3df25b89
|
File details
Details for the file gym_zelda_pygame-0.1.8-py3-none-any.whl.
File metadata
- Download URL: gym_zelda_pygame-0.1.8-py3-none-any.whl
- Upload date:
- Size: 2.5 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86eac3003f084b4846874542e46282f65c2b5157dd70a006d58b1206fc5f20ce
|
|
| MD5 |
fc0e4fc7211c3eb5b8004d2b4c7b5e93
|
|
| BLAKE2b-256 |
8f3e41b0578f6d7834766337151d11cff8b474fd15795ac13bd941b584158bdb
|