File size: 6,041 Bytes
a7b6153
 
 
 
 
 
 
 
 
 
 
 
fdcbf65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
---
title: AI Dungeon Game
emoji: ๐ŸŽฎ
colorFrom: indigo
colorTo: purple
sdk: gradio
sdk_version: 3.50.2
app_file: app.py
pinned: false
license: mit
---

# AI-Powered Dungeon Adventure Game

## Table of Contents
- [Overview](#overview)
- [Technical Architecture](#technical-architecture)
- [Key Features](#key-features)
- [Game Mechanics](#game-mechanics)
- [AI/ML Implementation](#aiml-implementation)
- [Installation](#installation)
- [Usage](#usage)
- [Project Structure](#project-structure)
- [Technologies Used](#technologies-used)
- [Future Enhancements](#future-enhancements)

## Overview
An advanced text-based adventure game powered by Large Language Models (LLMs) that demonstrates the practical application of AI/ML in interactive entertainment. The game features dynamic quest generation, intelligent NPC interactions, and content safety validation using state-of-the-art language models.

## Technical Architecture
- **Core Engine**: Python-based game engine with modular architecture
- **AI Integration**: Hugging Face Transformers pipeline for text generation
- **UI Framework**: Gradio for interactive web interface
- **Safety Layer**: LLaMA Guard for content moderation
- **State Management**: Dynamic game state handling with quest progression
- **Memory Management**: Optimized for GPU utilization with 8-bit quantization

## Key Features
1. **Dynamic Quest System**
   - Procedurally generated quests based on player progress
   - Multi-chain quest progression
   - Experience-based leveling system

2. **Intelligent Response Generation**
   - Context-aware narrative responses
   - Dynamic world state adaptation
   - Natural language understanding (NLP)

3. **Advanced Safety System**
   - Real-time content moderation
   - Multi-category safety checks
   - Cached response validation

4. **Inventory Management**
   - Dynamic item tracking
   - Automated inventory updates
   - Natural language parsing for item detection

## Game Mechanics
- **Dungeon Generation:** Randomly generated dungeons with obstacles.
- **Player and NPCs:** Players can move, fight NPCs, and use items.
- **Combat System:** Turn-based combat with simple AI decision-making.
- **Inventory Management:** Collect and use items to aid in your adventure.
- **Quest System:** Complete quests to earn rewards and progress through the game.


## AI/ML Implementation
1. **Language Models**
   - Primary: LLaMA-3.2-3B-Instruct
   - Safety: LLaMA-Guard-3-1B
   - Optimized with 8-bit quantization

2. **Natural Language Processing**
   - Context embedding
   - Response generation
   - Content safety validation

3. **Memory Optimization**
   - GPU memory management
   - Response caching
   - Efficient token handling

## Installation
```bash
# Clone repository
git clone https://github.com/prgrmcode/ai-dungeon-game.git
cd ai-dungeon-game

# Create virtual environment
python -m venv dungeon-env
source dungeon-env/Scripts/activate  # Windows
source dungeon-env/bin/activate      # Linux/Mac

# Install dependencies (`pip freeze > requirements.txt` to get requirements)
pip install -r requirements.txt
# Or install libraries directly:
pip install numpy matplotlib pygame
pip install python-dotenv
pip install transformers
pip install gradio
pip3 install torch torchvision --index-url https://download.pytorch.org/whl/cu118
pip install psutil
pip install 'accelerate>=0.26.0

# Create a .env file in the root directory of the project and add your environment variables:
HUGGINGFACE_API_KEY=your_api_key_here
```

## Usage
```bash
# Start the game
python main.py

# Access via web browser
http://localhost:7860
# or:
http://127.0.0.1:7860
```

## Project Structure
```
ai_dungeon_game/
โ”œโ”€โ”€ assets/
โ”‚   โ””โ”€โ”€ ascii_art.py
โ”œโ”€โ”€ game/
โ”‚   โ”œโ”€โ”€ combat.py
โ”‚   โ”œโ”€โ”€ dungeon.py
โ”‚   โ”œโ”€โ”€ items.py
โ”‚   โ”œโ”€โ”€ npc.py
โ”‚   โ””โ”€โ”€ player.py
โ”œโ”€โ”€ shared_data/
โ”‚   โ””โ”€โ”€ Ethoria.json
โ”œโ”€โ”€ helper.py
โ””โ”€โ”€ main.py
```

## Technologies Used
- **Python 3.10+**
- **PyTorch**: Deep learning framework
- **Transformers**: Hugging Face's transformer models
- **Gradio**: Web interface framework
- **CUDA**: GPU acceleration
- **JSON**: Data storage
- **Logging**: Advanced error tracking

## Skills Demonstrated
1. **AI/ML Engineering**
   - Large Language Model implementation
   - Model optimization
   - Prompt engineering
   - Content safety systems

2. **Software Engineering**
   - Clean architecture
   - Object-oriented design
   - Error handling
   - Memory optimization

3. **Data Science**
   - Natural language processing
   - State management
   - Data validation
   - Pattern recognition

4. **System Design**
   - Modular architecture
   - Scalable systems
   - Memory management
   - Performance optimization

## Future Enhancements
1. **Advanced AI Features**
   - Multi-modal content generation
   - Improved context understanding
   - Dynamic difficulty adjustment

2. **Technical Improvements**
   - Distributed computing support
   - Advanced caching mechanisms
   - Real-time model updating

3. **Gameplay Features**
   - Multiplayer support
   - Advanced combat system
   - Dynamic world generation

4. **Visual Enhancements**
   - **Graphical User Interface (GUI):** Implement a GUI using Pygame to provide a more interactive and visually appealing experience.

   - **2D/3D Graphics:** Use libraries like Pygame or Pyglet for 2D graphics.

   - **Animations:** Add animations for player and NPC movements, combat actions, and other in-game events.

   - **Visual Effects:** Implement visual effects such as particle systems for magic spells, explosions, and other dynamic events.

   - **Map Visualization:** Create a visual representation of the dungeon map that updates as the player explores.


## Requirements
- Python 3.10+
- CUDA-capable GPU (recommended)
- 8GB+ RAM
- Hugging Face API key




This project showcases practical implementation of AI/ML in interactive entertainment, 
demonstrating skills in LLM implementation, system design, and performance optimization.