Choose Your AIdventure
AI & GamingDestaque

Choose Your AIdventure

An AI-powered text RPG built for the Cloudflare AI Challenge, where every scene is narrated and illustrated by the same models running it.

15 de maio de 2024
AI & Gaming
Tecnologias
Cloudflare Workers AINext.jsPrompt EngineeringEdge FunctionsImage Generation

Choose Your AIdventure

Built for the Cloudflare AI Challenge, this is a text-based RPG where the story, the choices, and the visuals are all generated on the fly by AI models running at the edge.

What it is

Players pick a scenario — medieval fantasy or cyberpunk sci-fi — choose a character class, and get dropped into a story that unfolds turn by turn. Each scene is narrated by Llama 3.1 and illustrated by SDXL Lightning, generating a widescreen pixel art image to match whatever just happened. NPCs get their own AI-generated 8-bit portraits. The whole thing runs on Cloudflare Workers AI for inference, with API calls hitting edge functions instead of a traditional server.

The interesting parts

The biggest challenge wasn't getting AI to tell a story — it was getting it to tell a good one. Left unconstrained, LLMs tend to ramble. So I built a pacing system that injects hidden directives into the system prompt based on turn count: a hook phase, a midgame conflict, a climax, and a forced resolution by turn ten. The AI doesn't "know" this is happening — it just receives increasingly urgent instructions about consequences and finality.

Structuring the output was the other non-trivial piece. The model returns labelled text (NPC:, NARRATIVE:, Choices:) which the frontend parses to extract NPC names for portrait generation, strip formatting from the displayed text, and populate the choice buttons — all from a single response.

The scenario system is config-driven, so adding a new adventure type is mostly just writing a new entry in scenarios.ts and a system prompt.

What I learned

This started as a submission to understand Cloudflare's AI ecosystem — Workers, Pages, and their hosted models. It taught me how to work within the constraints of a specific provider's model catalog rather than defaulting to OpenAI, and how prompt engineering decisions compound quickly when the AI output is doing multiple jobs at once (narrative, UI data, image prompt).

The dev.to write-up reached ~500 readers in the week following the challenge.

Mais Projetos

Explore outros projetos no meu portfólio

© 2026 Paulo H. Alkmin. Todos os direitos reservados.