Doing a small browser roguelike at 2am and the generated dungeons kept producing rooms with no doors or whole sections cut off from the start. Classic naive procedural gen.
Asking for "random rooms and corridors" gave me disconnected blobs every time. What fixed it was forcing the algorithm choice (rooms + a spanning tree of corridors) and demanding a guaranteed-connectivity pass with a flood fill assertion. I also made it add a few extra loops so the map isn't a boring tree.
Posting the prompt and the one refinement that made the layouts feel designed rather than random.
Write a procedural dungeon generator in vanilla JS rendered on a 2D canvas as a tile grid (single file). Deterministic given a seed (implement a small seedable PRNG, e.g. mulberry32).
Algorithm (follow this, don't improvise a blob generator):
1. Grid 80x50 tiles. Place 8-14 non-overlapping rectangular rooms of random size (5-12 wide, 4-9 tall) with 1-tile padding between them.
2. Build a graph of rooms, compute a minimum spanning tree over room centers, and carve L-shaped corridors along every MST edge so EVERY room is reachable.
3. Add loops: carve 15% of the non-MST edges back in so the dungeon has cycles, not a pure tree.
4. Connectivity assertion: run a flood fill from the start room over floor tiles; if any floor tile is unreachable, throw an error. The generator must guarantee full connectivity.
5. Place a start room (farthest-pair heuristic) and an exit room far from it; scatter enemies/loot weighted by distance from start.
Rendering: simple tileset (wall/floor/door/start/exit), a torch-style light radius around the player, and fog of war that reveals as you move with WASD. Show the seed in the corner and let '1' reroll with a new seed. Keep generation under 20ms for the default size. Before the code, describe the connectivity guarantee in one paragraph.