Shadow Kingdom

A dynamic, AI-powered text adventure game with region-based world generation

Project Overview

Shadow Kingdom is an interactive text-based adventure game that uses AI to generate rich, atmospheric rooms and connections within thematically coherent regions. Players explore a mysterious fantasy kingdom where each area tells a cohesive story through connected spaces, from grand manor estates to ancient crypts and mystical gardens.

Built with Node.js and TypeScript, the game leverages Grok AI to create immersive experiences that adapt and expand as players explore. The sophisticated region-based generation system ensures that each area maintains thematic consistency while offering unexpected discoveries.

View on GitHubGet Started
Node.js
TypeScript
SQLite
Grok AI
Text Adventure
Procedural Generation

Key Features

🏰 Region-Based World Generation

Thematically coherent areas (mansions, forests, caves, towns) with distance-based transitions. Each region maintains consistent atmosphere while offering unique exploration opportunities.

🤖 AI-Generated Content

Rooms, descriptions, and connections dynamically created by Grok AI with regional context. Every space feels hand-crafted while being generated on-demand.

⚡ Background Generation

World expands automatically as you explore - new rooms generate in real-time without interrupting gameplay flow.

🧭 Dual Navigation System

Navigate using cardinal directions ("north") or atmospheric descriptions ("through the crystal archway") for immersive exploration.

💾 Persistent Worlds

Save and load multiple game sessions with SQLite database. Your adventures persist between sessions with full world state preservation.

📍 Region Discovery

Explore region centers containing important content and NPCs. Each region has meaningful destinations and story elements to discover.

🎯 Session Interface

Programmatic command execution for automation and testing. Perfect for scripted interactions and external integrations.

🏛️ Visit-to-Lock System

Rooms maintain consistent layout after first visit, creating a believable world that players can mentally map and navigate reliably.

Technical Architecture

Shadow Kingdom is built with a sophisticated architecture that balances AI creativity with performance and reliability. The system uses region-based probability models to ensure thematic coherence while providing endless exploration possibilities.

Core Components

GameController: Main game logic and command processing
RegionService: Region-based world generation and management
GrokClient: AI integration for content generation
SessionInterface: Programmatic command execution
Database: SQLite database wrapper with comprehensive schema

Data Model

Games: Session management with metadata
Regions: Thematic areas with types and descriptions
Rooms: Generated spaces with AI content
Connections: Bidirectional links with dual addressing
Game State: Player position and session tracking

AI Integration Strategy

The game uses Grok AI strategically to generate contextual content that enhances immersion. The AI receives adjacent room descriptions and regional themes to create coherent, atmospheric spaces. Distance-based probability transitions ensure natural region changes while maintaining exploration variety. Fallback systems provide graceful degradation when AI generation fails.

Gameplay Experience

Shadow Kingdom creates immersive text-based adventures through AI-generated content. Each exploration reveals atmospheric descriptions, thematic connections, and coherent world-building that adapts to player choices.

Example Adventure
> look

Grand Entrance Hall
===================
You stand in a magnificent entrance hall that speaks of forgotten grandeur. 
Towering marble columns stretch up to a vaulted ceiling painted with faded 
celestial murals...

Exits: through the ornate archway beneath celestial murals (north), 
through the glass doors that shimmer with moonlight (east), 
up the stone steps to the winding tower (west)

> region

Current Region: Shadow Kingdom Manor
Type: mansion
Description: A grand manor estate shrouded in mystery, filled with elegant 
halls, ancient libraries, and moonlit gardens where forgotten secrets await discovery.
Distance from center: 0
Total rooms in region: 6
Center room: Grand Entrance Hall

> go through the glass doors

Development Highlights

Building Shadow Kingdom involved solving complex challenges in AI content generation, world state management, and creating believable procedural worlds. The project showcases advanced TypeScript patterns, database design, and AI integration techniques.

Region-Based Generation

Implemented a sophisticated probability system where distance from region centers influences transition chances. The 15% base chance plus 12% per distance unit creates natural exploration patterns while maintaining thematic coherence.

Database Architecture

Designed a comprehensive SQLite schema with automatic triggers for region center discovery and bidirectional connection management. The system efficiently handles complex spatial relationships and game state persistence.

AI Integration

Developed context-aware prompting strategies that provide AI with regional themes, adjacent room descriptions, and spatial constraints. This results in coherent, immersive content that feels hand-crafted.

Session Interface

Created a programmatic command interface that enables automation, testing, and external integrations while maintaining the full interactive experience. Perfect for scripted adventures and development workflows.