So something like this? (I'm guessing that you have one button that jumps lanes, so to speak, and don't want the ambiguity of a crossroads, right?)
XXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXX..............XXXXXX
XXXXXXX.XXXX.XXX.XXX.XXXXXX
XXX..................XXXXXX
XXX.XXXXX.XXXXXX.XXXXXXXXXX
XXX..............XXXX....XX <= 2
XXXXX.XXXXX.XXXX.XXXX.XX.XX
XX.......................XX
XX.XXXX.XXXXX.XXXX.XXXXXXXX
XX.................XX1XXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXI'm also assuming that you don't want a three-way junction like:
X.X
X..
X.XOr a dead end like:
XXXXXX
.....X
X.XXXX(Not that it really matters. Just for concreteness' sake. Although no-dead-ends is easier.)
This could also be generated linearly in a single pass. At each step, you just need to know:
- the values of a few already-generated cells, the left, left-above, above, above-right, left-left, above-above, and above-right-right. (Those are the ones I can foresee, but there might be a cleverer way to use fewer.)
- the dimensions of the plane, so that you don't start generating a new hallway complex when there's not going to be the possibility of later hallways to connect it up, and know when you have to stop a horizontal hallway. Like you can't start a new hallway at (1) or else it will be stranded; there's got to be a margin where the normal "go ahead and start a hallway" rule can't apply.
- the parity (odd or even) of the current row. If you always do horizontal hallways on odd rows, then even if you start a new hallway complex out to the east (as in 2) and later run a horizontal hallway over to it, they line up properly. Otherwise there's the chance you get a multiple-square-tall vertical or horizontal hallway.
- the column number of the last empty cell in the previous row. You need this on odd rows, so that you don't cease extending a horizontal hallway before it joins up with the last vertical hallway of the previous row. (This is inelegant and eliminates some otherwise entirely ok layouts, but I can't think of an easier way to guarantee that all generated hallway complexes join up, not without rules that constrain possible layouts even more strictly.
Anyway, that's a fun exercise, I enjoyed it.
Let me know if you want the specific rules for the layout style above.