Perhaps a simpler (but not complete) solution would be to store some metadas of each "room / function" that you created. If you choose a wall at the end of the corridor, since placing any new function excludes the βcorridorβ as a real function.
This will not solve every inconsistency of the map, and if you have two different corridors (wider and narrower), you will never see the corridor getting wider or narrower, but this is a simple fix and a fairly quick fix.
Of course, there are ways to better solutions, but I would need to get more detailed information about this algorithm. For what I see in the link, you sent what it does is to select the wall plate as the placement and put a function on it. Maybe when choosing a placement you do not need to look only at the wall tile, which is chosen randomly, but for the entire solid wall around it:
- Choose a random function (corridor in the example for assembly)
- Choose a random wall tile somewhere
- You will learn from each function how great its discovery is.
- Compare if there are enough tiles for the tile (or to the right) to accurately place your hole, if not, select the wall up / to the right of the original selections and try again. You can get into a scenario where this is not possible, you can start all from point 1 and try again.
This is just above my head, of course, there are other solutions. But it may be good enough to get you started.
source share