I also made some small fixes to problems that I'd seen. In the old model, the hallways started big, and then always got smaller. This had the effect that hallways would just get very small very fast. Now, the hallway starts at a medium width, and each child can get bigger or smaller. This has the effect of making sure that there is a better distribution of large and small corridors.
I also changed the order in which children are drawn to create a more regular look. Now, child hallways are processed depth-first, starting with children nearest to the starting point of the parent hallway. Midway through last week, this had me creating dungeons that looked like this:
My first attempt involved backtracking along each corridor after building it and its children. Essentially, after a corridor finished building, it would begin to erase itself until it reached a room or a corridor that led to a room. I was unable to get this method to work. It mostly just erased all or almost all of the corridors. No good.
Take two was much more successful. First, the maze algorithm above is applied, including unnecessary hallways. Then a second draft is drawn, which gets rid of the unnecessary pathways. While the rough draft is being drawn, each corridor keeps track of whether or not it leads to a room or to a corridor that leads to a room. When a corridor draws a room, it remembers the position of that room as a potential end-point. It then updates its parent and tells the parent to end at the start of the child corridor. After the rough draft is done, each corridor knows whether or not it leads to a room. Corridors that lead off to nowhere are not drawn. The corridors that are drawn know the position of their most distal room or corridor that leads to a room. When these corridors are being redrawn, they use this information to prevent corridors from being too long.
As you can see, the trimmed map looks much more tame and is much easier to navigate. All of the rooms are in the same place, and every room is still accessible from every other room. Every now and again, a corridor goes one square too far (you can see one such instance in the upper right quadrant of the map), but I'm not particularly concerned by this occasional off-by-one error.
Now that I've got a nice, sane dungeon map generator, I can set about rendering it in 3D in Unity. This will be my task for next week. I do not anticipate it being too difficult, as it is fairly similar to what I did last semester.
EDIT: Also, just in case anyone was curious about run times, I did a test where I generated 1000 trimmed mazes, and measured the average time it took to make a maze. Here are the results:
40x40 maze w/ minimum 20 rooms: .0055 seconds per maze
40x40 maze w/ minimum 30 rooms: .0919 seconds per maze
NOTE: 30 rooms in a 40x40 maze is about as many as can fit.
100x100 maze w/ minimum 50 rooms: .0289 seconds per maze
100x100 maze w/ minimum 100 rooms: 4.375 seconds per maze (Averaged based on generating 50 mazes - didn't want to wait over an hour to generate 1000 mazes.)
The minimum number of rooms limit is enforced by checking the number of rooms after a maze has been generated, and restarting the maze if there are too few rooms. The running times get large if a maze has to start over a lot before a suitable maze is created. So running times can be said to be roughly proportional to minrooms/totalsquares.
Considering that the maze must only be generated once at the start of a level, these generation times are very reasonable. Even the 100x100 maze with minimum 100 rooms took an average of less than 5 seconds. An extra 5 second wait on top of the rest of the load time is not an unreasonable amount of time to expect the player to wait.
If you want to see one of the 100x100 with minimum 100 rooms mazes, you can see one here. (Download the .txt file and then open it in your text editor of choice.)
EDIT: Also, just in case anyone was curious about run times, I did a test where I generated 1000 trimmed mazes, and measured the average time it took to make a maze. Here are the results:
40x40 maze w/ minimum 20 rooms: .0055 seconds per maze
40x40 maze w/ minimum 30 rooms: .0919 seconds per maze
NOTE: 30 rooms in a 40x40 maze is about as many as can fit.
100x100 maze w/ minimum 50 rooms: .0289 seconds per maze
100x100 maze w/ minimum 100 rooms: 4.375 seconds per maze (Averaged based on generating 50 mazes - didn't want to wait over an hour to generate 1000 mazes.)
The minimum number of rooms limit is enforced by checking the number of rooms after a maze has been generated, and restarting the maze if there are too few rooms. The running times get large if a maze has to start over a lot before a suitable maze is created. So running times can be said to be roughly proportional to minrooms/totalsquares.
Considering that the maze must only be generated once at the start of a level, these generation times are very reasonable. Even the 100x100 maze with minimum 100 rooms took an average of less than 5 seconds. An extra 5 second wait on top of the rest of the load time is not an unreasonable amount of time to expect the player to wait.
If you want to see one of the 100x100 with minimum 100 rooms mazes, you can see one here. (Download the .txt file and then open it in your text editor of choice.)

