And there were a few issues with it. The first is that we had a lot of non-connected tiles. My first gut instinct was to just remove the dead ends at the tilesheet image–which, I may not have mentioned, is just a 90×6 image, and every 6×6 ‘box’ of pixels represents a particular connection–ends, T junctions, etc. The first four of these are the dead-end connections. To remove them, I first tried doing just that: taking the T junctions and just copy/pasting over the dead ends with them, I get this:
Better, but it still looks a little off. The problem now is that we’ve got ‘islands’ of connected segments, and it looks a little weird. After some staring blankly at the screen, the I decided to fix this I’d have to actually work with code, specifically, this code:
New = 0
current = array[row,col] #current type is a numpy.int32, not plain old python int
current = '%04d' % int(bin(current)[2:]) #net result is a 4 digit binary string
#pull out the 4 digit binary string from each adjacent tile
try: top = '%04d' % int(bin(array[row-6,col])[2:])
except IndexError: top = None
#check if adjacent tile 'wants' to connect
if str(left)=='1' or current == '1':New+=8#;print "catch right"
if str(top)=='1' or current == '1':New+=4#;print "catch bottom"
Sooo, what does this all do? Put simply, it scans through the matrix and changes predefs so that they appear joined by changing one of the 0's in the four bit long number to a 1 to match the adjacent predef. To explain further:
First, I'll note that I added some redundant code that could (should?) have gone into a function and made this thing about 4 times smaller; I just left out the redundant parts where it checks the other 3 directions for both cases.
The first bit of code is where the function takes the current cell in an array (defined as array[row,col]), and using the line
'%04d' % int(bin(number)[2:]) converts a "numpy int" (NOT a regular int, oddly) into a binary number that is then sliced and padded and converted into a string all at once and formatted. Long story short, it takes a number like 6, and turns it into a string of "0110". Then, we do that for the cell found to the left, right, bottom, and top of the current cell (top is the only operation shown). Try/Except syntax lets me fudge it so that if I try to get a bad index it just doesn't go through, instead of quitting with an IndexError.
Once we do that, we enter the second part of the function, where what happens is that we are effectively OR'ing the value of "current" in binary with the corresponding digit of each adjacent tile, and that result is fed into the int New by adding binary's significant figures accordingly (8=1000, 4=0100, etc). This is where the cells are actually coordinated into being joined. Outside of the function, the value of 'current' is then replaced with that of New when the function is called.
...well that's a little different. Something I didn't mention was that along the way is that I've been fudging the dimensions a little, now I'm up to 6x6 pixel sets of predefs and everything is bigger. Regardless, I'm closer to making a reasonable'ish network of hallways, but now the opposite problem is happening than before: the map is now just a plain old grid and is too connected, and that's not interesting. So how about we add a condition that predefs are joined only, say, 50% of the time? Well we do that, and end up with:
It looks a little better. There seem to be definite sections of hallways, and I can almost see where rooms could be set via those grids. Looking back at that online dungeon map generator, I've noticed 2 distinct types of connections: hallway connections, and room connections. I'm not sure where I'm going with this at this point, but if I make more headway with this and find a way to reasonably explain it, I'll post next about getting rooms in here.