My C++ professor recently gave us an assignment to read in a text file of 0s and 1s into a 2d array as a rectangular maze, and then traverse the maze by following a wall.
As an extra he challenged us to come up with a random maze generator. I worked for hours on this but could not come up with an algorithm that gives suitable "maze-ness" (solid clusters of walls, and gaps, connectivity and dead ends) He said it doesn't matter if it looks like a maze or not, but I was still intrigued..
good maze bad mazes
11111111 11111111 11111111
10110000 10101000 10001000
10100011 00101101 10000001
00001001 11010101 00000101
11111111 11111111 11111111
I tried all sorts of tricks like XORing neighboring values to create
walls and hallways, to no avail. My current algorithm simply creates a frame of 1s, element is set to (rand() % 3)%2 + '0' (seems to yield best results by experimentation) and then an entrance and exit pathway is cleared on either side. It generates rather pathetic mazes!
Some possible ideas which I haven't tried yet:
- a random first pass, and then a second pass which randomizes again with probability based on the surrounding squares.
- fill entirely with 1s and then create some sort of "boring" algorithm which works like a blind search function which wanders around twisting and turning, until an exit is found.
I know there are 'real' algorithms out there by professors and PHDs but I'm interested in your original ideas.. bonuses for elegance and simplicity over mathematical rigor, and incorporating seemingly unrelated ideas.. anyone?
As an extra he challenged us to come up with a random maze generator. I worked for hours on this but could not come up with an algorithm that gives suitable "maze-ness" (solid clusters of walls, and gaps, connectivity and dead ends) He said it doesn't matter if it looks like a maze or not, but I was still intrigued..
good maze bad mazes
11111111 11111111 11111111
10110000 10101000 10001000
10100011 00101101 10000001
00001001 11010101 00000101
11111111 11111111 11111111
I tried all sorts of tricks like XORing neighboring values to create
walls and hallways, to no avail. My current algorithm simply creates a frame of 1s, element is set to (rand() % 3)%2 + '0' (seems to yield best results by experimentation) and then an entrance and exit pathway is cleared on either side. It generates rather pathetic mazes!
Some possible ideas which I haven't tried yet:
- a random first pass, and then a second pass which randomizes again with probability based on the surrounding squares.
- fill entirely with 1s and then create some sort of "boring" algorithm which works like a blind search function which wanders around twisting and turning, until an exit is found.
I know there are 'real' algorithms out there by professors and PHDs but I'm interested in your original ideas.. bonuses for elegance and simplicity over mathematical rigor, and incorporating seemingly unrelated ideas.. anyone?