Member-only story
Adding Key Placement to a JavaScript Roguelike
Can we write an algorithm that makes all rooms accessible?
In most video games, any level should allow the player to reach the goal. While that may sound obvious, it’s easier said than done in a roguelike, where levels are procedurally generated. While making each level solvable was never a problem in the early stages of building Rogue of Rhondar, it became a challenge after adding doors and keys. This article discusses the series of tests and refinements that ultimately led to my current key placement algorithm.
Getting Oriented
Below is a quick screenshot of the in-progress game.
So far, each level in this game is procedurally generated and consists of the following:
- rooms connected by hallways
- locked doors
- small keys
- enemies
- a relic, which must be found to complete the
The keys in the game are called “small keys” because any key can unlock any door, and each key can only be used once. Below is a quick clip of the player…