A 2D dungeon game built from scratch in Python where enemies learn using Reinforcement Learning.
Not just a game — an AI experiment you can play.
AI Enemy Dungeon Game is a 2D top-down dungeon game developed using Python + Pygame, where enemies are powered by Reinforcement Learning (Q-Learning).
Unlike traditional games with fixed enemy behavior, enemies in this game learn from player actions, adapt strategies, and become smarter over time.
🎯 This project is designed for:
- 🧑🎓 Students & beginners in AI
- 🎮 Game development learners
- 🤖 Understanding Reinforcement Learning visually
- 📂 Portfolio & GitHub showcase
The game begins with a clean and minimal start menu.
▶️ Press ENTER to start the game- 🎨 Simple UI for instant understanding
During gameplay, the player sees a real-time HUD showing:
- ❤️ Player Health
- ⭐ Score
- 📈 Level Progression
- 🧠 Enemy Learning Status
You control the player using keyboard controls.
- ⌨️ Controls: W A S D
- 🚶 Smooth movement
- 🧱 Boundary-restricted inside the dungeon
Enemies are not scripted — they learn using Q-Learning.
Enemy behavior includes:
- 🔁 Observing player position
- 🎯 Choosing actions (CHASE / RUN / ATTACK)
- 📊 Receiving rewards & penalties
- 🧠 Improving decisions over time
The enemy’s learning is saved and loaded automatically using pickle.
The dungeon world is created using a tile-based map system.
- 🟩 Repeating floor tiles
- 📐 Grid-based movement
- 🎨 Pixel-art style environment
As the score increases:
- ⬆️ Level increases
- 👾 New enemies spawn
- ⚡ Difficulty increases
This ensures replayability and challenge.
- 💥 Collision sound using
pygame.mixer - 🎧 Improves game feel and feedback
| Key | Action |
|---|---|
| ENTER | Start Game |
| W A S D | Move Player |
| R | Restart Game |
| Close Window | Exit Game |
- 🐍 Python
- 🎮 Pygame
- 🧠 Reinforcement Learning (Q-Learning)
- 💾 Pickle (AI memory)
This project demonstrates that:
- ✅ Games can teach AI concepts
- ✅ Reinforcement Learning can be visual
- ✅ Python is powerful for game + AI projects
⭐ If you like this project, consider giving it a star!




