Catface Games

Basic Map Generation

by Derek (2026-10-09)

Let's talk about map generation.

A staple of roguelikes is procedural map generation: using randomness to design the dungeon as you play. There's a historical reason for this. At the time of Rogue's development and release, the memory needed to store hand-crafted maps wasn't available. Like roguelikes themselves there is emergent behavior that benefits the designer. You can't learn the map while play testing and will play it as your players will.

So what's the simplest algorithm we can imagine? We could generate a rooms at random (both size and location). But, we need to connect them. We can just connect each room (after the first) to the previous room. We're working on a grid, so direct lines are complicated. Instead, we'll randomly choose either drawing a vertical hallway followed by a horizontal one, or a horizontal hallway followed by a vertical one. Let's take a look at some python flavored pseudocode for this:

prevRoom = randomRoom()
for _ in range(maxRooms):
    room = randomRoom()
    room.connect(prevRoom)
    prevRoom = room
  
Thank you, Bresenham.

Well, it's a start. But those blobs where rooms overlap aren't great. Fortunately, that's an easy fix. We'll just keep track of the rooms we've placed, and ignore any rooms that would overlap.

prevRoom = randomRoom()
rooms.append(prevRoom)
for _ in range(maxRooms):
    room = randomRoom()
    if any(room.intersects(r) for r in rooms):
        continue
    room.connect(prevRoom)
    rooms.append(room)
    prevRoom = room

That solves our room intersection issue. What about those hallways? That's more complicated. It doesn't look great, but what it does give us is that there are multiple paths between rooms. And that's a good thing. It makes the map feel less linear. This is probably the simplest algorithm that we could have for generating a map. That's probably why it's the algorithm used by the Roguelike Tutorial. Next time, we'll take a look at another method for generating maps.

Want to find out about future posts before they go live? Join the mailing list