I'm having a bit of trouble developing code to figure out which doors connect in Rogue which is written in c. Not the actual path making. I just dont understand how they link to each other.

If rooms have 2 doors each then, while not the cleanest solution, I can connect the first rooms door1 to the second rooms door2 and continue that pattern, finally going around in a loop.

However, say there are 3 doors for one room, then that would break because one door wouldnt connect to anything. The same thing goes for a one door room.

Any help would be appreciated and links to examples would help too.



I'm not really generating paths right now, its more of the player teleporting to another door. If it were paths then of course it could intersect which takes care of the paths.

  • \$\begingroup\$ Are you required to only make one connection from any door to any other door? If not, you could have two doors connect to a third door, but the third door only goes to one of the others. In other words, can you have doors A and B both go to door C, and door C only go to door A? This would allow you to follow @Alexandre Vaillancourt 's answer and still deal with an odd number of doors. \$\endgroup\$
    – fnord
    Mar 19, 2015 at 22:14

2 Answers 2


Imagine dots are doors and lines are corridors. This is how you can have three doors connected:

steiner tree

There is no reason why you can't link a door to more than one other door. You can have corridors merge at some point.

But oldskool roguelikes didn't even do this; they simply connected random pairs of rooms with corridors, and if they happen to cross into a room, boom, open a door here. This is the reverse process of what you're thinking. You can easily see how, since each corridor creates exactly two doors, this never produces a third door, so the problem never appears.

But why limit yourself to these methods? There is a wealth of possibilities on the PCG wiki. Maze generation alone is a well-studied field and has numerous algorithms.

  • \$\begingroup\$ I'm not really generating corridors at the moment. I'm just teleporting from one door to the other, thats why I'm trying to figure out which door is connected to what. If there were 3 doors to a room then my code breaks. If I was making paths then I do understand your logic \$\endgroup\$
    – Exikle
    Mar 19, 2015 at 19:50
  • \$\begingroup\$ So my end result was basically this, where I made 2 doors connect and if someone went through a third door it'd just move you to one of the doors. It worked so I'm happy for now \$\endgroup\$
    – Exikle
    Apr 4, 2015 at 4:17

Here is another way to connect rooms with three doors:

  1. Make sure the amount of doors in your level is even.
  2. Put all your rooms in the not-door'd set
  3. Pick two rooms from the not-door'd set
  4. Connect them through one of their doors
  5. If those rooms still have a door that has no corridor, put them in a partially-door'd set
  6. While the not-door'd set is not empty, pick one room from the partially-door'd set and one from the not-door'd and repeat from step 4, otherwise, proceed to next step
  7. While the partially-door'd set is not empty, pick two rooms from the partially-door'd and repeat from step 4, otherwise, your done

This should work for rooms with any number of doors; all the rooms should be connected to the labyrinth, but some could be connected to themselves. And you might have issues if you have more than one room that has only one door :P

  • \$\begingroup\$ That makes sense but, I'm using a txt file which has predeterminned positions for the doors to generate the dungeon. What happend of there are odd amount of doors \$\endgroup\$
    – Exikle
    Mar 19, 2015 at 18:33
  • \$\begingroup\$ Ahh, then connecting to corridors like suggested by @congusbongus seems like a good way to do it! \$\endgroup\$
    – Vaillancourt
    Mar 19, 2015 at 18:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .