Building the Procedural Dungeon Generator

Dungeon Crawl ·

A deep dive into how we built the procedural dungeon generation system using BSP trees and cellular automata.

The Challenge

When we set out to build Dungeon Crawl, one of the first major systems we tackled was the procedural dungeon generator. We wanted levels that felt hand-crafted but were different every time.

BSP Trees for Room Placement

Our approach starts with Binary Space Partitioning (BSP) trees. The algorithm recursively splits the dungeon area into smaller rectangles, then places rooms within each leaf node. This guarantees good spatial distribution without rooms overlapping.

The key parameters we tuned were:

  • Minimum room size - too small and rooms feel cramped, too large and the dungeon feels empty
  • Split ratio - how evenly each partition divides. A 50/50 split creates uniform grids; randomising this creates more organic layouts
  • Recursion depth - more splits means more, smaller rooms

Cellular Automata for Caves

For cave-like areas, we switched to cellular automata. Starting with random noise, we apply smoothing rules over several iterations. Cells with many neighbours become walls; isolated cells become floor. After 4-5 iterations, you get natural-looking cave systems.

Connecting It All

The trickiest part was connecting BSP rooms to cave sections seamlessly. We use A* pathfinding to carve corridors between room centres, then apply a dilation pass to widen narrow passages.

What’s Next

In the next devlog, we’ll cover the enemy AI system and how enemies navigate these procedural layouts.