The floor is generated, every room is reachable, and now one room has to hold the boss. Put it in the wrong one and the run deflates: the player opens the second door and walks straight into the final fight, or the boss sits beside the entrance behind a single wall.
The usual answer is "the room farthest from the start". That is right, as long as you measure farthest the way the player travels. This is part 6 of a series that builds one dungeon generator, pass by pass.
Why "farthest" needs a definition
There are two ways to measure how far a room is from the entrance:
- On the grid. Count the cells across plus the cells down between the two room centres, ignoring walls. This is called Manhattan distance, after a city's grid of streets. It is one line of code and needs no map.
- On foot. Walk the corridors, the way the player will. A flood fill from the entrance gives every floor cell its walking distance in steps.
On a level with straight, direct corridors, the two agree. On a generated level, corridors go where the generator put them, so they often disagree.
Seed 214, measured both ways
Farthest on the grid, or farthest on foot?
Interactive, engine-accurateMeasured on foot, the boss goes in room 7. On the grid, room 5 looks farthest: 18 cells away. But it is only 18 steps on foot. Room 7 is 15 cells away on the grid and 43 steps on foot, the real longest walk.
| Room | On the grid | On foot |
|---|---|---|
| 1 | 11 cells | 11 steps |
| 2 | 13 cells | 23 steps |
| 3 | 8 cells | 12 steps |
| 4 | 8 cells | 8 steps |
| 5 | 18 cells (farthest) | 18 steps |
| 6 | 18 cells | 28 steps |
| 7 | 15 cells | 43 steps (farthest) |
| 8 | 17 cells | 39 steps |
S is the entrance (room 0) and B is where each rule puts the boss. With On foot, the shading is the flood fill: the darker the floor, the longer the walk. With On the grid, the dashed line is the distance the grid rule measures, straight through rock.
This runs the GDScript from this article, ported to the browser. The same seed gives the same result in Godot 4.7.2.
On seed 214, room 5 is the farthest on the grid: 18 cells from the entrance. It is also 18 steps on foot, because a fairly direct corridor leads there. Room 7 is only 15 cells away on the grid, closer than room 5. But walking there takes 43 steps, because the corridors wind down to room 6 and back up the far side of the map.
So the grid rule would put the boss in room 5, with the long walk to room 7 left as an optional detour. The walking rule puts the boss at the end of that long walk. Across seeds 1 to 500 of this generator, the two rules pick different rooms on 229, close to half.
What else to check
The longest walk is a good default, not a complete answer. Three more checks catch most bad boss rooms:
- A minimum distance. On a small floor, or one where something cuts off the far rooms, even the farthest reachable room can be close. The generator in this series rejects a level when the boss is fewer than 12 steps away. Its layouts never fail that on their own: the shortest farthest walk on seeds 1 to 500 is exactly 12. But it fails on 10 of those seeds once crates are dropped anywhere, because crates in doorways cut off the far rooms.
- Nothing behind it. If the boss room is the only way into another room, that room becomes after-the-boss content, usually by accident. Flood fill again with the boss room treated as solid. Every other room should still be reached.
- One way in. A boss room with two doors can be walked around. If you want a single arena entrance, prefer rooms with one doorway, or close the extra doors.
The playability test in part 8 turns these into automatic checks.
The same distances do more than pick the boss
Once you have walking distances, they answer other placement questions for free:
- Difficulty that grows with distance. Scale each room's enemies by how far it is from the start, so the run builds towards the boss.
- Rewards on the way. Put a treasure room off the main route, at the end of a side branch, so finding it is a choice.
- Safe rooms. A shop or rest room roughly halfway along the walk to the boss gives the run a breather.
RogueBasin calls a map of distances like this a Dijkstra map, and uses the same numbers for enemy movement too.
In Godot: two ways to pick the room
The grid version only needs the room rectangles. get_center() returns the middle cell of a Rect2i, and manhattan() adds up the steps across and down:
func farthest_room_on_grid() -> int: var start := rooms[0].get_center() var best := 0 var best_distance := -1 for i in rooms.size(): var d := manhattan(start, rooms[i].get_center()) if d > best_distance: best_distance = d best = i return bestThe walking version reads the distances a flood fill already worked out. walk_distances() is the flood fill from part 3:
func farthest_room_on_foot(dist: PackedInt32Array) -> int: var best := 0 var best_distance := -1 for i in rooms.size(): var d := dist[index(rooms[i].get_center())] if d > best_distance: best_distance = d best = i return bestSwitching an existing generator from one rule to the other is a two-line change: run the flood fill once, then pick by dist instead of by manhattan(). An unreachable room has a distance of -1, so it can never win.
The complete generator is dungeon_layout.gd.
Build it next
Procedural Dungeon & Run
A quest on CodingQuests: 12 interactive lessons that build one part of a game in Godot, in your browser, checked as you go.
Lesson 9 of Procedural Dungeon & Run places the cast. It puts the boss in the room farthest from the entrance on the grid, the Manhattan rule above, and grows the enemy packs with distance. Lesson 11 adds the boss key and the locked door. Both are member lessons.
To use walking distance instead, swap the Manhattan line in lesson 9 for a flood fill, as shown above. The course does not include that change.
- Lesson 9: Placing the CastMembers
- Lesson 11: Gold, the Boss Key & the Locked DoorMembers
Lessons 1 to 3 are free to open, no account needed. Guild Hall, the membership, opens the other 9.
FAQ
Where should the boss room go in a procedural dungeon?
In the room that is the longest walk from the entrance, measured along corridors with a flood fill. Then check that walk is long enough and that no other required room is only reachable through the boss room.
Why does my farthest room end up close to the start?
Because it was measured in a straight line, or on the grid, through solid rock. A room can be far away in a straight line and still be a short walk, or the other way round. Measure walking distance instead.
How do I find the farthest room from the player in Godot?
Run a breadth-first flood fill from the player's cell over the floor cells, storing steps per cell. Then read the step count at each room's centre and keep the largest.
Sources and testing
- Amit Patel, Red Blob Games: distance fields with breadth-first search
- RogueBasin, The Incredible Power of Dijkstra Maps
- Godot docs: Rect2i.get_center()
- A related developer question: How to add "boss room" to dungeon generator? on Unity Discussions. We found no question asking exactly where to put the boss, so this topic is our own pick.
How this was tested. The GDScript on this page was run in Godot 4.7.2 (headless, on Windows) on 31 October 2026. The demo runs a browser port of the same script, checked against Godot's output on 40 seeds. The 500-seed counts come from that port. The 10 boss-too-close failures also appeared when the same 500 seeds were run inside Godot.

