With our characters ready to move, the final milestone of Phase 1 was to give them a world worth exploring. I have successfully implemented a 3-Pass Procedural Generation System that transforms a 5 x 5 grid into a 25-room “Space-Filling” gauntlet.

The Generation Sequence

To ensure the world is both random and traversable, the GameController executes a strict generation pipeline every time a level begins.

Step 1: The Challenge of the Hamiltonian Corner-Start

The most significant technical hurdle was enforcing the Corner-Start Constraint. The MazeIDGenerator is programmed to begin its Backtracking Depth-First Search (DFS) at a specific corner node.

  • The Complexity: Starting in a corner reduces the initial degrees of freedom. The algorithm must be robust enough to “snake” through the entire 5 x 5 grid without trapping itself in a dead-end before the 25th room is reached.
  • The Result: This ensures the player always begins in a predictable location (Room 0), allowing the GameController to reliably spawn the player inside the map rather than the void.
Step 2: Dungeon Pass 1 (Prefab-Based Inhabitation)

Once the path is validated, the DungeonCreator populates the world using a modular Prefab System:

  • The Anchor Room: The first room in the sequence is always instantiated as a “Large Room” prefab to provide a consistent starting hub.
  • Spatial Variation: The remaining 24 rooms are randomized between three scale variants (10, 15, or 20 units).
  • Modular Potential: By using prefabs for every room, I’ve ensured that we can later spawn randomized props, lighting setups, and enemy spawners into each “container” without altering the base generation code.
Step 3: Dungeon Pass 2 (The Bridge & UV Polish)

Connecting rooms of different sizes on a grid creates variable gaps. To solve this, I developed a “Bridge” pass:

  • Dynamic Corridor Prefabs: The script calculates the edge-to-edge distance between rooms and scales a Corridor Prefab to bridge the gap exactly, with a 0.05 unit overlap to prevent light leaking.
  • Technical Polish (UV Tiling): To prevent textures from stretching on these dynamic bridges, I implemented a custom UV tiling calculation. This keeps the visual density of the walls and floors consistent, regardless of the corridor’s length.
Step 4: Pass 3 (Special Objects & The Game Loop)

Finally, the “Rules” are applied into the map:

  • The Exit Goal: An Exit Portal prefab is spawned in the 25th and final room of the sequence.
  • The Level Reset: Upon hitting the portal trigger, the currentLevel increments, a brand-new seed is rolled, and the entire dungeon—and its 25-room path—is rebuilt instantly.

Technical Skills Demonstrated
  • Graph Theory: Implementing Backtracking DFS for Hamiltonian pathfinding.
  • Modular Prefab Architecture: Designing a system ready for prop randomization and custom art placement.
  • Advanced Math: Edge-to-edge distance calculations and dynamic UV tiling.
  • Data Structures: Using Dictionaries for O(1) room look-up and spatial management.

The Mathematics of the Labyrinth

To understand the replayability of Project Labyrinth, we can look at the combinatorial complexity of the generation system. By combining graph theory constraints with modular spatial variation, the system produces an astronomical number of unique layouts from a very small pool of hand-authored assets.

VariableMetricTechnical Context
Grid Dimensions5 x 525 potential nodes for inhabitation.
Path Logic1,012Unique Hamiltonian paths starting from a corner node.
Spatial Variation324Random variations of Small, Medium, and Large room prefabs.
Total Unique Dungeons285+ TrillionUnique physical dungeon configurations.

Finalizing Phase 1

With this system, the “foundation” of Project Labyrinth is officially complete. We have animated heroes and a procedurally generated world for them to conquer.

Stay tuned for Dev Log #4, as we head into Phase 2: The Campfire & Persistence. I’ll be breaking down how we save this generated data to JSON and how players can finally swap their character class mid-run at the campfire hub.