|Why put a spike trap there? (Source: ACWells)|
Procedural generation means gamers cannot hop on Twitter to scream at game developers—because there’s no developer to scream at. The game generates the levels. AAA studios use it in games like Far Cry 6 to produce new terrain. Minecraft, the best-selling game globally, procedurally generates the entire world. Every new level is completely unique to the player.
Rouguelike is a game subgenre based on procedural generation. The game generates a level/run/entire world for the player, who dies or wins. After that, the level is lost forever. Back at the starting menu, the player begins a new run on a completely different level or world.
Roguelikes are difficult, and I'm addicted. They prove you have skill—you can't memorize every level and go from point A to B. Situations are similar but never exactly the same, so learn or die. You earn every victory. One of my favorites is Spelunky, a retro platformer made by Derek Yu. There are plenty more to be found on Steam.
In his book, not surprisingly named Spelunky (available on Amazon), Yu explains how procedural generation works. The game has to make a beatable level or the player won’t return to the game. The process starts with the script scrLevelGen making a 4 × 4 grid of rooms. Then it makes a winnable main path by:
- Randomly choosing a room on the top row as an entrance.
- Randomly choosing left, right, or down to continue the path.
- Randomly stopping on the bottom row, marking an exit room.
Spelunky’s procedural generation at work. (Source: Priestman)
Now scrRoomGen fills both the main path and any unselected side rooms with templates that work. If the script just slapped blocks anywhere, there's no way to guarantee the level is beatable. That’s why the process is called “procedurally generated” and not “randomly generated”—there are clear constraints and rules the engine follows.
The last script is the fun one, called scrEntityGen. The script checks for empty tiles to spawn in monsters, gold, traps, etc. This can put money or health off the main path, and you have to choose if you want to risk resources to gain more.
Three scripts make an infinitely replayable game. Far Cry 6 is using a lot more tech to procedurally generate its foliage, but most engines follow this idea: a generator with rules.
In his book, Yu laments that the “system doesn't create the most natural-looking cave” and “the player will quickly begin to recognize certain repeating landmarks.” This can be a major flaw of procedural generation. Letting the engine go too wild compromises the gameplay, but too many restrictions will make a repetitive slog. Savvy readers will remember the criticism of No Man's Sky's launch: Why do these randomly generated planets randomly look the same?
At the end of the day, procedural generation makes for infinitely replayable games and an infinite number of deaths for my spelunker. Every time I die to an arrow trap, I remember next time to drop a rock down to eat the arrow instead. Now I can get thousands of hours of gaming with just three games in my library.
Thank you, procedural generation.