The engine is authoritative, the LLM only narrates
Dice, combat and story state are deterministic code. The model receives resolved events and returns prose, so outcomes are reproducible and testable and the AI cannot cheat or contradict the rules.
Personal project
Dark-fantasy text RPG where a deterministic engine rules and an LLM narrates
The player acts, the engine resolves it against chapter data, emits events and saves; the narrator turns those facts into text through the server route, or locally if the LLM fails.
Click a step to jump to it. Click a component for details.
A browser-based, bilingual dark-fantasy RPG with character creation, turn-based D20 combat, puzzles, inventory and a multi-chapter campaign. The game engine owns every rule and outcome, while an LLM turns resolved events into narration and generates new chapters that must pass schema and playability validation before they can be played.
The problem
LLM-driven games drift: models forget the campaign, invent outcomes and break rules. The goal was an AI Dungeon Master that is expressive but can never change authoritative game state.
Dice, combat and story state are deterministic code. The model receives resolved events and returns prose, so outcomes are reproducible and testable and the AI cannot cheat or contradict the rules.
Moving chapters into a standard validated format removes hardcoded ids from the engine and makes new chapters, including LLM-generated ones, safe to load and verifiable offline.
The browser calls a Next.js API route which holds the API key and talks to the provider, keeping the secret server-side and the client simple.
Puzzles never call the LLM and share one shape across engine, validator and chapter contract, so progression can't stall on a bad generation.
The server never returns a chapter that has not passed both the schema and the full reachability validator, so a bad generation returns an error (422) instead of a broken campaign.