Spielerando

Procedural Dungeons

A procedural dungeon is made from a seed number, so the same seed always gives the same dungeon. Rooms are placed without touching, joined left to right so all of it can be reached, then checked. A failed dungeon is made again from the same random sequence, and after enough failures a plain, safe one is used.

Also called: Random dungeons, Generated levels, Seeded maps.

A tiny beetle explorer with an amber lantern watches carved stone blocks and arches float into place to build a new chamber, in a black-and-white scratchboard cutaway of a labyrinth with a teal glowing exit far away.
Gravelbrook Warrens, an invented scratchboard dungeon crawler. Invented game, image generated with AI.

Paste this to your AI

Copy it into Claude, Cursor or ChatGPT. It already has good values and the usual mistakes in it.

Add "Procedural Dungeons" to my game.

What it should do: A new dungeon every run keeps a game fresh without a level designer for every floor. A seed makes it repeatable, so a player can share a run and you can replay a bug, and a check makes sure no dungeon is ever impossible to finish.

Build it exactly as this state machine. First check that it fits my game, then build it like this:

```mermaid
stateDiagram-v2
  [*] --> placing
  placing: Placing rooms
  linking: Joining rooms
  checking: Checking
  ready: Ready
  placing --> linking: enough rooms
  linking --> checking: all joined
  checking --> placing: failed, try again
  checking --> ready: good dungeon
  ready --> [*]
```

Use these starting values:
- width: 40 cells
- height: 24 cells
- roomCount: 8 rooms
- maxRoomSize: 8 cells
- minExitDistance: 25 cells
- maxAttempts: 20 tries

Watch out for these common mistakes:
- Using the clock for randomness: Tell your AI: keep the random sequence inside the dungeon's own state and start it from the seed, never from the clock.
- Starting again with the same seed: Tell your AI: when a try fails, carry on with the next numbers of the same sequence, not the seed again.
- A dungeon that cannot be finished: Tell your AI: join the rooms in a line first, then check that every floor cell can be reached and that the exit is far enough.
- A job that never ends: Tell your AI: count the tries, and after the last one use a plain dungeon that always works.
- Rooms too big for the map: Tell your AI: cut the biggest room size down to what fits inside the walls before picking.
- Too many rooms wished for: Tell your AI: stop placing after a fixed number of tries per room, and count a dungeon as too small below about three fifths of the wish.
- Odd seeds: Tell your AI: turn the seed into a whole number first, and use zero for anything that is not a number.

Do not change anything else in the game. Do not claim anything without proof: model what it takes, and show me what your solution rests on and how I can see that it works. If you cannot show something, say you do not know. When you are done, tell me in plain words how to try it.

Or skip this and connect the MCP: your AI then finds all of this by itself.Connect the MCP

What it does

A new dungeon every run keeps a game fresh without a level designer for every floor. A seed makes it repeatable, so a player can share a run and you can replay a bug, and a check makes sure no dungeon is ever impossible to finish.

How it runs, as a diagram

Everything it can be in, and what moves it on. Your AI builds from exactly this.

enough roomsall joinedfailed, try againgood dungeonPlacing roomsJoining roomsCheckingReady
How it runs, as a diagram
  • Placing rooms → Joining rooms: enough rooms
  • Joining rooms → Checking: all joined
  • Checking → Placing rooms: failed, try again
  • Checking → Ready: good dungeon

Good starting values

ValueStart withWhat it changes
width40 cellsHow wide the dungeon is. Forty cells leaves room for about eight rooms with space to walk between them.
height24 cellsHow tall the dungeon is. Wider than tall fits a screen better.
roomCount8 roomsHow many rooms to try for. The dungeon may end up with fewer if they do not fit, but never fewer than about three fifths of this.
maxRoomSize8 cellsThe longest side a room can have. Rooms are never smaller than 3 cells. Bigger rooms make fewer, roomier dungeons.
minExitDistance25 cellsHow far the exit must be from the start along the paths. A dungeon where the exit is next door is dull.
maxAttempts20 triesHow many dungeons to try before the plain one is used. Twenty is plenty on a normal map and still finishes quickly.

What usually goes wrong

Using the clock for randomness

If the dungeon is made from the clock or a global random generator, the same seed gives a different dungeon each time and bugs cannot be replayed.

Fix: Tell your AI: keep the random sequence inside the dungeon's own state and start it from the seed, never from the clock.

Starting again with the same seed

A failed dungeon that is retried from the same seed fails in exactly the same way, for ever.

Fix: Tell your AI: when a try fails, carry on with the next numbers of the same sequence, not the seed again.

A dungeon that cannot be finished

Rooms joined by chance can leave a part cut off, and an exit placed at random can be right next to the start.

Fix: Tell your AI: join the rooms in a line first, then check that every floor cell can be reached and that the exit is far enough.

A job that never ends

If the demands cannot be met on a small map, trying again and again never finishes and the game hangs on a loading screen.

Fix: Tell your AI: count the tries, and after the last one use a plain dungeon that always works.

Rooms too big for the map

A room that is bigger than the map allows has no place to go, and the random pick of a position breaks.

Fix: Tell your AI: cut the biggest room size down to what fits inside the walls before picking.

Too many rooms wished for

A small map with a large wish for rooms never reaches it, and a dungeon with two rooms is hardly a dungeon.

Fix: Tell your AI: stop placing after a fixed number of tries per room, and count a dungeon as too small below about three fifths of the wish.

Odd seeds

A seed of zero, a negative number or a broken value can turn the random sequence into the same number every time.

Fix: Tell your AI: turn the seed into a whole number first, and use zero for anything that is not a number.

How to check it works

Works well with

Common questions

how do i make random dungeons that are always possible to finish

Place rooms at random, join them in a line from left to right, and check the result: every floor cell reachable and the exit far from the start. If the check fails, try again from the next random numbers. After a set number of tries, use a plain dungeon that always works.

what is a seed and why does a dungeon need one

A seed is the starting number of the random sequence. The same seed always gives the same dungeon, so players can share a run and you can replay a bug. Never use the clock inside the dungeon maker.

why does my random dungeon sometimes trap the player

Rooms joined by chance can leave a part cut off. Join every room to the next one in a line first, add loops afterwards, and test that every floor cell can be reached from the start.

what do i tell my ai to add procedural dungeons

Paste this: Add procedural dungeons made from a seed. The random sequence lives in the state, never the clock. Place up to 8 rooms of 3 to 8 cells that do not touch, join them from left to right plus one loop, then check that every floor cell can be reached and the exit is at least 25 cells from the start. If it fails, carry on with the same sequence. After 20 tries use a plain row of rooms.

Where it comes from

We could not find a reliable origin for this one yet.

Where this mechanic comes from has not been researched yet.

Games are named only as references. Names and marks belong to their owners, and nothing here is endorsed by them.

What was checked

This is what separates the blueprint from a catalogue entry: the values on this page come from code that runs.

Your AI gets the code

Tested example code comes through the Spielerando connection, so your AI can use it right away. How to connect it