There are all kinds of maze generating algorithms out there. This one of mine uses a pretty simple premise.
[1] Choose a random spot on the map
[2] If not first time, must be connected to existing corridor
[3] Choose a random direction to go (up, down, left, right)
[4] Is it "free" there ?
[5] Yes, cut a line from original to this place.
[6] No ? Try a different direction ?
[7] No directions are good ? We are completely stuck ? Exit here and GOTO [1]
[8] Line was cut, if not complete with maze, GOTO [3]
[9] Completed maze ? Mark entrance and exit and loop forever.
Written in only a little over 200-tokens, this is compact maze making code indeed. Oh, and if you check it carefully, you will see that it guarantees only ONE way through. No way to reach the exit from two-different paths at all.
Press CTRL-R to make a new different maze each time.
Source code gives option to show maze being carefully drawn.
[Please log in to post a comment]