Super Mario Bros 2 (Europe) Gymnasium Environment
Project description
smb2-gym
A Gymnasium environment for Super Mario Bros 2 (Europe/Doki Doki Panic version) using TetaNES emulator Python bindings. Perfect for reinforcement learning experiments and research.
Features:
- Curated action sets for faster training (
simple,complex) - Comprehensive game state via info dict (35+ properties)
- Multiple initialization modes (character/level, custom ROMs, save states)
- Human-playable interface with keyboard controls
- Up to 350+ and 750+ FPS rendered and non-rendered respectively
A somewhat comprehensive list of the available RAM map properties is available at Data Crystal, but this library includes many extras that are not documented anywhere.
Installation
pip install smb2-gym
Quick Start
Basic Usage
from smb2_gym import SuperMarioBros2Env
from smb2_gym.app import InitConfig
# Create environment with character/level mode
config = InitConfig(level="1-1", character="luigi")
env = SuperMarioBros2Env(
init_config=config,
render_mode="human", # "human" or None
action_type="simple" # "simple" (11), "complex" (16), or "all" (256)
)
# Reset environment
obs, info = env.reset()
# Run game loop
for _ in range(1000):
action = env.action_space.sample()
obs, reward, terminated, truncated, info = env.step(action)
# Access game state from info dict
print(f"Lives: {info['life']}, Hearts: {info['hearts']}")
print(f"Position: ({info['x_pos_global']}, {info['y_pos_global']})")
if terminated or truncated:
obs, info = env.reset()
env.close()
Initialization Modes
from smb2_gym.app import InitConfig
# 1. Character/Level mode (default)
config = InitConfig(level="1-1", character="peach")
# 2. Built-in ROM variant mode
config = InitConfig(rom="prg0", save_state="level_1_1.sav")
# 3. Custom ROM mode
config = InitConfig(
rom_path="/path/to/your/smb2.nes",
save_state_path="/path/to/save.sav" # Optional
)
Custom Reward Function
from smb2_gym import SuperMarioBros2Env
from smb2_gym.app import InitConfig
class CustomSMB2Env(SuperMarioBros2Env):
def step(self, action):
obs, reward, terminated, truncated, info = super().step(action)
# Custom reward based on x-position progress
reward = info['x_pos_global'] / 100.0
# Bonus for collecting cherries
reward += info['cherries'] * 10
# Bonus for hearts
reward += info['hearts'] * 5
# Penalty for losing a life
if info.get('life_lost'):
reward -= 100
return obs, reward, terminated, truncated, info
# Usage
config = InitConfig(level="1-1", character="luigi")
env = CustomSMB2Env(init_config=config, action_type="simple")
Play as Human
The package includes a human-playable interface with multiple initialization modes:
Character/Level Mode (Default)
# Play as Luigi on level 1-1
smb2-play --level 1-1 --char luigi --scale 3
# TODO: Yet to implement all levels states
# Play as Peach on level 2-3
smb2-play --level 2-3 --char peach
Built-in ROM Variant Mode
# Use specific ROM variant with save state
smb2-play --rom prg0_edited --save-state easy_combined_curriculum.sav
Custom ROM Mode
# Use your own ROM file
smb2-play --custom-rom /path/to/smb2.nes
# Use custom ROM with save state
smb2-play --custom-rom /path/to/smb2.nes --custom-state /path/to/save.sav
# Start from beginning without save state
smb2-play --custom-rom /path/to/smb2.nes --no-save-state
Controls
Primary Controls:
- Arrow Keys: Move
- Z: A button (Jump)
- X: B button (Pick up/Throw)
- Enter: Start
- Right Shift: Select
- P: Pause
- R: Reset
- ESC: Quit
Alternative Controls:
- WASD: Move
- J: A button
- K: B button
Save States:
- F5: Save state
- F9: Load state
CLI Options
Character/Level Mode:
--level: Level to play (1-1 through 7-2, default: 1-1)--char: Character (mario, luigi, peach, toad, default: luigi)
Built-in ROM Mode:
--rom: ROM variant (prg0, prg0_edited)--save-state: Save state filename
Custom ROM Mode:
--custom-rom: Path to custom ROM file--custom-state: Path to custom save state (optional)--no-save-state: Start from beginning without loading save state
Display:
--scale: Display scale factor (1-4, default: 3)
Disclaimer
This project is for educational and research purposes only. Users must provide their own legally obtained ROM files.
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 smb2_gym-0.2.11.tar.gz.
File metadata
- Download URL: smb2_gym-0.2.11.tar.gz
- Upload date:
- Size: 364.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c656761773e5c80f4e9e0def6e3eb3ec635993fdb338500f3331c939bb4bf76
|
|
| MD5 |
2af1313f35837b7109397c654615778d
|
|
| BLAKE2b-256 |
edb473f51cb1ec27772cd99c33407b5a964709ba63083b4668b13a7fd47a03f2
|
File details
Details for the file smb2_gym-0.2.11-py3-none-any.whl.
File metadata
- Download URL: smb2_gym-0.2.11-py3-none-any.whl
- Upload date:
- Size: 360.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
440eb2dbcb1e67847ad018948b2d56bb4b2cda63e6df04cc7fe38625ce8b772b
|
|
| MD5 |
2d28f5cff5f6e6a2c048da3a449198ca
|
|
| BLAKE2b-256 |
97427f939093af257ad7d23e714fcbfe4c8373d5cbdea0cb542f1c39e20083eb
|