Skip to main content

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.

Installation

gym-zelda-pygame is published on PyPI. Install with:

pip install gym-zelda-pygame

Environment Details

Spaces

  • Action Space: Discrete(8) 0) no-op

    1. move up
    2. move down
    3. move left
    4. move right
    5. attack
    6. magic
    7. 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.001 per step (encourage efficiency)
  • Health changes: penalty for loss, small reward for gain
  • Experience gain: small positive reward
  • Enemy defeats: large positive reward (+10.0 per 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

Respect the original projects’ licenses and assets. This environment is an RL wrapper around their codebase to support education.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gym_zelda_pygame-0.1.9.tar.gz (2.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gym_zelda_pygame-0.1.9-py3-none-any.whl (2.5 MB view details)

Uploaded Python 3

File details

Details for the file gym_zelda_pygame-0.1.9.tar.gz.

File metadata

  • Download URL: gym_zelda_pygame-0.1.9.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

Hashes for gym_zelda_pygame-0.1.9.tar.gz
Algorithm Hash digest
SHA256 7299842b6eb7384779ea1d0341496703f6f8bb124f552ebe82b87b677abd1f8b
MD5 3e11bc59227abec84d4aebd4a9efa829
BLAKE2b-256 a0a77c4d2e38c5ed44e638f3799dc119f49f5d01393d74b5b1584be6e4b43597

See more details on using hashes here.

File details

Details for the file gym_zelda_pygame-0.1.9-py3-none-any.whl.

File metadata

File hashes

Hashes for gym_zelda_pygame-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 0c756a5b6cd783b2df11ae5437cba531ce789807fa8a70c2e967be6570b43dbd
MD5 b96340b15d52ee2cace67ac61644d971
BLAKE2b-256 3434e3a76ae72cee41e579498056fe424995184a781f2d4331f6febf7ca0c815

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page