CHAPTER 38: The Maze That Builds Itself (Patreon)
Content
CHAPTER 38: The Maze That Builds Itself
Castlevania was a castle George built stone by stone. Each room designed by hand, each enemy placed with intention, each corridor connected to the next with the precision of a watchmaker assembling gears. The player traversed a world that existed complete before he pressed Start, a world where every corner was planned and every surprise was, paradoxically, planned.
Isaac could not work like that.
Isaac was a roguelike. A game where each run generated a new map, with new rooms, new enemies, new items, new challenges. A player who died and started from scratch would not see the same basement twice. Infinite replayability was the game's reason for being, far more than a bonus. If Isaac generated the same map every time, it was an action game with permadeath, which was a frustrating concept. If it generated different maps every time, it was a game where dying worked as an invitation to try again, far from any punishment, because the next run was going to be different, and different meant new possibilities, new combinations, new moments.
The problem was that "random" and "good" were not synonyms.
George knew it from experience. He had played roguelikes in his previous life, hundreds of hours in games like Spelunky, Enter the Gungeon, Dead Cells, and the original Binding of Isaac itself, and the difference between an addictive roguelike and a frustrating one was always in the procedural generation. A good generator created maps that felt hand-designed even though they were random: each room had a purpose, each path had risk and reward, each run told a different but coherent story. A bad generator created empty corridors, dead ends, unfair distributions of items, and the feeling that a computer was rolling dice instead of building a world.
George was going to build a good generator. And for that he had to solve a problem that sounded simple and was abyssal: how do you make a computer design levels that feel as if a human had designed them?
*
George started with the most basic thing: the structure of the map.
He opened the blue Isaac notebook to a new page and drew a grid. Nine squares by nine squares. Eighty-one cells. Each cell could be empty or contain a room. Adjacent rooms, the ones that shared a border, were connected by doors.
It was the simplest possible structure for an Isaac map: a 2D grid where rooms were placed like dominoes following adjacency rules. It was abstract, flat, and removed from the simulation of a real cave or basement. And the abstraction was intentional: Isaac was not trying to simulate a realistic architectural space. It was trying to create a play space that was legible, navigable, and variable.
George defined the parameters of the first floor, the Basement, in the notebook:
Grid: 9x9 cells.
Minimum rooms per floor: 7.
Maximum rooms per floor: 12.
Required rooms: 1 spawn room (where Isaac starts), 1 boss room (where the floor's boss is), 1 item room (where there's a passive item), 1 shop (a store to buy with coins), 1 secret room (a hidden room accessible by breaking a wall).
Optional rooms: between 2 and 7 normal rooms with enemies.
Seven to twelve rooms distributed across a grid of 81 cells. Most of the grid would be empty. The occupied rooms would form an irregular pattern, like a constellation of stars in a black sky, connected by doors the player crossed walking from one to another.
George programmed the data structure that first morning. A two-dimensional array of 9 by 9 where each cell contained a room ID or a null value. Each room had four door flags: north, south, east, west. If two adjacent rooms existed, both had the corresponding door active. It was simple, clean, and fast to query: to know whether there was a room north of the current position, all you had to do was look at the cell above in the array.
But the data structure was just the skeleton. The soul was the algorithm that filled the grid.
*
George called the first algorithm "the drunkard" because it worked like a drunk walking through a city: it took a step in a random direction, then another, then another, leaving a trail of rooms behind it.
The process was simple:
1. Place the spawn room in the center of the grid (cell 4,4).
2. Choose a random direction: north, south, east, or west.
3. Move one cell in that direction. If the cell is empty, place a room there. If it's occupied, choose another direction.
4. Repeat from the new position until reaching the floor's room count.
5. Place the boss room in the room farthest from the spawn room.
6. Place the special rooms (item room, shop, secret room) in random positions that satisfy certain rules.
George implemented the drunkard algorithm in an afternoon. He ran it a hundred times and looked at the results in the console: text grids where the dots were empty cells and the letters were rooms, with S for spawn, B for boss, I for item, $ for shop.
The results were instructive. And horrible.
The drunkard produced maps that were technically functional, there was always a path from the spawn to the boss, but that felt like what they were: random paths with no design. The rooms lined up in long, thin lines, like an infinite hotel corridor, because the drunkard tended to walk in the same direction for several steps before turning. There were no branches. There were no loops. There was none of the feeling of exploring a complex space with multiple paths and decisions.
George looked at the hundred maps printed on paper, he had printed them because looking at text grids on a CRT screen was destroying his eyes, and saw what was missing: structure. The drunkard generated paths. Isaac needed maps.
*
The second iteration was what George called "the tree."
Instead of a single path that snaked through the grid, the tree grew branches. The algorithm started at the spawn room as before, but at each step it had the possibility of doing two things: advance in a direction (like the drunkard) or branch, create a new branch that departed from the current position in a different direction.
The branches created options. Instead of a linear corridor, the player reached intersections where he could go left or right, each path leading to different rooms with different enemies and items. Exploring stopped being advancing in a straight line and became making decisions: do I go left where I see an item room or right where the boss is?
George programmed the tree and ran a hundred iterations. The maps were better. They had shape: branches that created options, short dead ends that ended in rewards, alternative paths to the boss that offered longer routes but with more items. They looked, for the first time, like maps of a game and not diagrams from a math class.
But they had a new problem: the dead ends.
The tree's branches ended abruptly. The player entered a branch, went through three or four rooms, and reached a wall. He had to turn around and retrace the path back to the intersection. In a fast-action roguelike where every second counted, retracing your steps was a waste of time that broke the rhythm.
George needed loops. Paths that connected to each other so the player always had an alternative exit instead of having to backtrack.
*
The third iteration was the one that worked. George called it "the explorer," although in his head it was a mix of three ideas he had distilled from the roguelikes he remembered and from his own experience as a level designer.
The explorer worked in three phases.
Phase 1: The main path. The algorithm generated a path from the spawn room to the boss room using a modified random walk: a path that favored turns, removed from the straight line and the drunkard, that avoided long lines, and that had a length proportional to the size of the floor. For the Basement, the main path had between 5 and 7 rooms.
Phase 2: The branches. From the main path, the algorithm generated side branches 1 to 3 rooms long. The branches departed from random rooms of the main path and grew in perpendicular directions. Each branch ended in a special room (item room, shop) or in a normal room with enemies. The branches were optional: the player could ignore them and go straight to the boss, or explore them to look for items and coins.
Phase 3: The loops. After generating the main path and the branches, the algorithm looked for opportunities to connect rooms that were in adjacent cells but did not have a door between them. If two existing rooms shared a grid border, there was a 30% chance the algorithm would open a door between them, creating a loop: an alternative path that connected two parts of the map. The loops eliminated the dead ends and created the feeling of an interconnected space.
George programmed the explorer in three days. It was the hardest code he had written for Isaac: harder than the rendering engine, harder than the movement system, because the procedural generation was an operation that ran once, instead of repeating every frame, and whose result defined the entire experience of the player for the next thirty or forty minutes.
If the generator produced a good map, the player would have a good run. If it produced a bad map, there would be no game mechanics or items or synergies that could save it. The map was the foundation. Everything else was built on top.
*
Before testing the generator, George implemented a system that was going to be invisible to 99% of the players but that was essential for the 1% who were going to become obsessed with Isaac: the seeds.
A seed was a number, a 32-bit integer, which meant more than four billion possible values, that fed the game's random number generator. Every random decision the generator made, which direction to take, where to place a branch, whether to open a loop, which enemies to put in each room, which items to leave in each item room, depended on the sequence of numbers the generator produced, and that sequence was completely determined by the seed.
Which meant that if two players used the same seed, they got exactly the same map. The same rooms in the same positions, with the same enemies, the same items, the same bosses. A reproducible experience within a random system.
What was that good for? For sharing. George had seen it in the original Isaac of his previous life: players shared seeds on forums as if they were secret codes. "Try seed 1234567: Brimstone in the first item room, Sacred Heart in the second, broken run in ten minutes." The seeds turned the individual experience into a communal one: hundreds of players could live the same run and compare results, discuss strategies, compete over who completed it fastest or with the highest item percentage.
George implemented the seed system in a morning. At the start of each run, the game generated a random seed based on the system clock. The player could see the seed on the pause screen (an eight-digit number) and type it into the start menu to reproduce a specific run. It was a small feature. It was going to be enormous.
*
The generator decided where the rooms went. But what was inside each room?
George solved this with room templates: predesigned rooms the generator selected from a catalog. Each template was a complete room with a fixed distribution of obstacles, a list of spawn positions for enemies, and a difficulty rated from 1 to 5.
The templates were pure design, decided by hand down to the last detail. Each was drawn by hand by George in the blue notebook and then implemented in the engine: the position of each rock, each pile of garbage, each hole in the floor, each elevated platform. Marcus and Priya created the tiles for each obstacle, and George assembled the templates as if they were pieces of a modular puzzle.
The Basement had forty templates in the first version: ten easy (open spaces with few obstacles, for the first rooms of the floor), fifteen medium (rocks and holes that divided the room into zones, forcing the player to navigate while dodging enemies), ten hard (narrow labyrinths with little room to maneuver), and five special (rooms with unique layouts that appeared only once per floor).
The key was that the player would never see the templates for what they were. Each template felt like a unique room because the enemies that spawned inside were different every time, the items they contained varied, and the position within the map changed. The same template could appear as the second room of one run and the second-to-last of another, and in both cases it felt different because the context was different: the player had different items, different health, different abilities.
It was design hidden inside randomness. The paradox of the good roguelike: each individual element was carefully designed, but the combination of those elements was unpredictable.
*
One Wednesday in May, at nine at night, George generated the first complete floor of Isaac.
He did not play it yet, the combat system was not implemented, nor the items, nor the enemies with working AI. What he did was generate the map and walk through it with a placeholder Isaac: a red square that moved through rooms full of gray rectangles (the obstacles) and yellow circles (the spawn positions of the enemies that did not yet exist).
Rectangles and circles. The way Castlevania had begun with a white rectangle.
But this time, the map was different. George pressed a key that regenerated the floor. The rooms reorganized. The obstacles changed position. The yellow circles appeared in other places. He pressed again. Another map. Another distribution. Another experience.
Ten times. Twenty. Fifty. George generated fifty floors and walked through each one with the red square, navigating among gray rectangles and passing through doors that opened to rooms that had not existed a second before.
The maps had shape. The abstract shape of a play space, more than the organic shape of a real basement: paths that branched, loops that connected different branches, short dead ends that ended in item rooms, the boss room always at the end of the longest route. Each map was different but they all felt coherent. Playable. Navigable.
Tomás appeared in the office doorway, he had stayed late doing QA on the PS2 port, and saw George in front of the screen generating maps.
"What's that?"
"Isaac. The floor generator."
"The red squares are the character?"
"Placeholder. The art comes later."
Tomás sat in the chair next to him and watched while George generated ten more maps. Then he said something George did not expect:
"Generate another."
George looked at him.
"Another. I want to see what comes out."
George pressed the key. Another map. Tomás studied it, going through the rooms with his eyes as if tracing a route in his head.
"Another."
George generated another. And another. And another. Tomás was hooked. He was hooked by the pure possibility, far from the graphics, there were no graphics, just rectangles and circles, and far from the action, there was no action, just a square moving through empty rooms. He was hooked by the fact that every time George pressed the key, something new appeared. Something that had not existed before. Something no one had seen or would see again unless they used the same seed.
"George," Tomás said, without taking his eyes off the screen. "If the final game feels like this but with enemies and items and things to blow up, people aren't going to be able to stop playing."
George looked at the screen. Gray rectangles and yellow circles on a nine-by-nine grid. The most primitive, ugliest, most abstract version of what Isaac was going to be. And Tomás, a QA tester whose job was to break games, could not stop asking for another map.
The generator worked.
*
That night, after Tomás left, George did a calculation in the blue notebook.
With the current parameters, a 9x9 grid, between 7 and 12 rooms per floor, 40 templates, 5 floors, and a 32-bit seed, the number of possible maps was astronomical. George did not try to calculate it precisely because the combinatorics were impossible to solve on paper, but a conservative estimate gave him more than a billion unique configurations for the Basement alone. Multiplied by five floors, the number of completely different runs was incalculable.
A billion basements. Each one different. Each one generated in a fraction of a second by an algorithm George had written in three days.
It was dizzying. And it was just the structure. There were still the enemies that would fill the rooms, the items that would define each run, the bosses that would await at the end of each floor. Each layer George added would multiply the possibilities exponentially, until the number of unique experiences Isaac could produce was, for all practical purposes, infinite.
Infinite. An infinite game made by a finite team in a two-hundred-square-meter office.
George closed the notebook. He looked at Marcus's mural on the back wall, barely visible in the gloom of the nighttime office. Dracula's castle with its roots and its towers. Isaac's basement to its left. The empty space to the right.
Castlevania was a castle with a fixed number of rooms George had placed one by one, like a bricklayer laying bricks. Isaac was a maze that built itself, different every time, infinite in its variations, built by an algorithm George had taught to think like a level designer.
They were not the same. They did not feel the same. They did not satisfy the same part of the brain. Castlevania was the satisfaction of exploring a perfect world where every detail was in its place. Isaac was the satisfaction of facing a world you did not know and could not memorize, where the only constant was your skill and your luck.
Two kinds of game. Two kinds of pleasure. Two kinds of design. And George was making both at the same time, in the same office, with the same team.
The maze that built itself was ready. Now it just needed to be filled with monsters.
End of Chapter 38