A simple AI-powered dungeon master that generates scenarios and handles player actions in a text-based RPG game.
This Python script simulates a classic text-based RPG experience where the AI acts as a Dungeon Master, generating dynamic scenarios and responding to player actions. The game features:
- Dynamic Scenario Generation: Random scenarios with various locations, creatures, characters, and objects
- Player Actions: Support for multiple action types including attack, run, talk, search, and heal
- Game State Management: Track player HP, gold, and inventory
- Natural Language Processing: Simple pattern matching to interpret player commands
- Turn-based Gameplay: Interactive loop that continues until the player dies or quits
- 🎲 Random scenario generation using templates
- ⚔️ Combat system with attack and defense mechanics
- 💰 Loot and treasure collection
- 🗣️ Character interaction and dialogue
- 🔍 Exploration and item discovery
- ❤️ Health and inventory management
- 📦 Simple yet engaging gameplay loop
python ai_dungeon_master.py- The game will present you with random scenarios
- Type your action in natural language (e.g., "attack the goblin", "search for treasure", "run away")
- The AI will interpret your action and respond with outcomes
- Monitor your HP and inventory
- Continue until you win, die, or quit
- attack/fight/strike: Engage in combat with enemies
- run/flee/escape: Retreat from danger
- talk/speak/negotiate: Interact with characters
- search/explore/investigate: Look for items and treasure
- heal/potion/rest: Use a potion to restore HP
- quit/exit/q: End the game
=== AI DUNGEON MASTER ===
Commands: attack, run, talk, search, heal, status, quit
Type your actions in natural language!
You enter a dark dungeon. A goblin attacks you!
HP: 100 | Gold: 50 | Items: sword, potion
What do you do? > attack
>>> You defeated the enemy! Gained 20 gold.
- Python 3.x
- No external dependencies (uses only standard library)
PLAYER: Dictionary storing game state (HP, gold, inventory)SCENARIOS: Template strings for scenario generationgenerate_scenario(): Creates random scenarios using templateshandle_action(): Processes player actions and returns outcomesdisplay_status(): Shows player's current statsmain(): Main game loop
- Lines of Code: Under 100 lines (excluding comments and blank lines)
- Pattern Matching: Uses regex for flexible command interpretation
- Randomization: Leverages Python's
randommodule for unpredictability - State Management: Simple dictionary-based player state
Possible improvements for future versions:
- Save/load game functionality
- More complex combat mechanics
- Persistent world state
- Character progression and leveling
- Multiple enemy types with different behaviors
- Quest system
- More detailed item management
This project is part of the 100 Lines of Python Code repository. Contributions and suggestions are welcome!
This code is provided as-is for educational and entertainment purposes.
This solution addresses issue #619: Make AI Dungeon Master for Roleplaying Games