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.

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.8.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.8-py3-none-any.whl (2.5 MB view details)

Uploaded Python 3

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

Hashes for gym_zelda_pygame-0.1.8.tar.gz
Algorithm Hash digest
SHA256 fe964460b76cac4d7bf04c74a005aa2ea50a42322a69c9b4843f4bd069155eae
MD5 bede9d83ffd4a01f4236c3891a0f7135
BLAKE2b-256 d0db4b85416fdb94989600e78013911cdd938964739ea7640141001a3df25b89

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gym_zelda_pygame-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 86eac3003f084b4846874542e46282f65c2b5157dd70a006d58b1206fc5f20ce
MD5 fc0e4fc7211c3eb5b8004d2b4c7b5e93
BLAKE2b-256 8f3e41b0578f6d7834766337151d11cff8b474fd15795ac13bd941b584158bdb

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