Skip to main content

Boltcrypt environment

Project description

BoltCrypt: Procedural Dungeon RL Environment

BoltCrypt is a lightweight, OpenAI Gymnasium-compatible environment featuring procedurally generated dungeons. It challenges Reinforcement Learning agents (and humans!) to navigate complex layouts, solve sokoban-style boulder puzzles, and manage inventory items like keys to reach the exit.

🏰 Features

Procedural Generation: Every reset generates a unique dungeon layout based on configurable parameters (density, connectivity, room size). Puzzle Mechanics: Includes boulder-pushing puzzles and locked doors that require finding a key. Gymnasium API: Fully compatible with standard RL workflows. Pygame Visualization: A built-in harness to play manually or watch your agent learn in real-time. Flexible Observation Space: Provides local room grids, global coordinates, and inventory status. 🛠 Installation Since this project uses condavenv, ensure you have your environment active:

# Example if using conda directly
conda activate <your-env-name>
pip install gymnasium pygame numpy matplotlib boltcrypt

🚀 Getting Started

Play Manually

Test the dungeon generation and mechanics yourself using the Pygame harness:

python -m boltcrypt.game.boltcrypt_game

Arrows: Move the agent. R: Reset/Regenerate the dungeon. Goal: Find the key (if required) and reach the green Exit tile.

Alternatively, play in a terminal-based CLI interface:

python -m boltcrypt.game.boltcrypt_cli

WASD/Arrow Keys: Move the agent. R: Reset/Regenerate the dungeon.

Train an Agent

The project includes a tabular Q-Learning implementation to demonstrate how an agent can "memorize" a specific dungeon layout:

python -m boltcrypt.examples.tabular_q

Benchmark Performance

Test environment speed with the included benchmark:

python -m boltcrypt.examples.speed_test

⚙️ Configuration

The DungeonGenerator and BoltCrypt environment can be customized via a config dictionary:

Parameter Description

min_dist: Minimum Manhattan distance between Start and Exit. mean_rooms: Average number of rooms in the dungeon. connectivity: Probability of creating loops between rooms (0.0 = Tree, 1.0 = Highly connected). puzzle_density: Chance of a room containing a boulder puzzle.
key_puzzle_prob: Chance that the exit is locked and a key is hidden in a leaf room.
randomize_end_distance: If True, randomizes the actual distance from min_dist to 2*min_dist.

🗺 Tile Legend

⬜ Floor: Walkable space.
⬛ Wall: Impassable.
🚪 Door: Transitions between rooms (may be locked by puzzles).
🟩 Exit: Your goal!
🔴 Switch: Target for boulders.
🟤 Boulder: Can be pushed onto switches.
🟡 Key: Required to open locked exit rooms.

🤖 Observation Space

The environment returns a dictionary:
grid: A 10x10 local view of the current room.
agent_pos: (x, y) coordinates within the room.
global_pos: (gx, gy) coordinates in the dungeon layout.
inventory: Binary flag (1 if holding a key)

📦 Wrappers & Extensions

BoltCrypt includes several gym.Wrapper implementations to modify observations or rewards, making it a versatile testbed for different RL paradigms.

📝 Natural Language Wrapper (NaturalLanguage)

The crown jewel for testing Reasoning LLMs. This wrapper transforms the numeric observation space into a rich, descriptive narrative. Instead of a grid, the agent receives a text-based description of its surroundings.
Dynamic Narrative: Provides room dimensions, relative positions of doors, boulder locations, and puzzle statuses (e.g., "A loud mechanical clank echoes! The doors unlock.").
LLM Ready: Accepts string inputs like "NORTH", "SOUTH", "EAST", or "WEST" in the step() function.
Physics Logic: Includes an "Adventurer's Manual" to explain game rules to an LLM via the observation stream.

🌫️ Fog of War (FogOfWar)

Transforms the global room view into a partially observable environment.
Vision Range: Limits the grid observation to a (2v+1) \times (2v+1) window centered on the agent.
Memory Challenge: Forces agents to map the room internally rather than having perfect spatial information.

🏆 Room Discovery Reward (RoomDiscoveryReward)

Combats sparse rewards in large dungeons by incentivizing exploration.
Exploration Bonus: Grants a small configurable reward (e.g., +0.1) the first time the agent enters a new room in the dungeon.
Global Navigation: Helps agents learn the layout of the "macro-dungeon" before they’ve found the final exit.

🛠 Usage Example
You can stack wrappers to create complex experimental setups:

import gymnasium as gym
from boltcrypt.env import BoltCrypt
from boltcrypt.wrapper import NaturalLanguage, RoomDiscoveryReward

env = BoltCrypt()
env = RoomDiscoveryReward(env, discovery_reward=0.5)
env = NaturalLanguage(env)

# Now the agent receives text and extra rewards for exploration!
obs, info = env.reset()
print(obs) 

action = "NORTH"
obs, reward, done, trunc, info = env.step(action)

Happy Dungeon Crawling! 🗝️🏹

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

boltcrypt-0.1.2.tar.gz (28.9 kB view details)

Uploaded Source

Built Distribution

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

boltcrypt-0.1.2-py3-none-any.whl (30.8 kB view details)

Uploaded Python 3

File details

Details for the file boltcrypt-0.1.2.tar.gz.

File metadata

  • Download URL: boltcrypt-0.1.2.tar.gz
  • Upload date:
  • Size: 28.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for boltcrypt-0.1.2.tar.gz
Algorithm Hash digest
SHA256 b85dadbae9aabee9ac6a45a4d3bf049f290b21b79b47436e4261ce81a4bde839
MD5 5b76492631096c840c85bece4e1b8fe4
BLAKE2b-256 663a3efeaf5f291e0e8aec30a8f874803efb998753794b0c2a4ff55c9cfb0571

See more details on using hashes here.

Provenance

The following attestation bundles were made for boltcrypt-0.1.2.tar.gz:

Publisher: python-publish.yml on foreverska/BoltCrypt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file boltcrypt-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: boltcrypt-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 30.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for boltcrypt-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7be8d1853e1645352bc363d2564873edcc04b84df9aab4ee961305b882f86049
MD5 51223a5364a1643995d5129911087c42
BLAKE2b-256 e8c0e0dcc225b2b6ccd44423f00b3f6422f85725007cb1b0191395eba0913759

See more details on using hashes here.

Provenance

The following attestation bundles were made for boltcrypt-0.1.2-py3-none-any.whl:

Publisher: python-publish.yml on foreverska/BoltCrypt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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