Goal
I am making a program which generates a 3D maze and am having a bit of trouble with the creation algorithm. For ease of interaction, it will be a rectangular prism with one entrance and one exit.
Algorithm
The problem is the actual coding of the algorithm: I figured the best way to go with this is make a class called MazeBlock
, which has six boolean states (up, down, left, right, in, out) which signify in which direction the maze can go next. using a 3D array of MazeBlock
s, I want to fill the maze, each iteration of filling checking the blocks to the left, right, above, below, in front of, and behind it to see if there is any opening to that side to which to attach.
I already have one that will make the edges, placing random open slots toward the interior of the maze. All I have trouble with is the actual interior, ensuring that the maze has one entrance, one exit, and one solution to traverse it (I once solved a "difficult" 3D maze in a popup book by going only a few steps opposite the intended direction.
Question
As I siad, I think I have the basic idea for the algorithm, but I don't know how to code it. Can someone come up with a Java algorithm for this that accomplishes the task relatively quickly?
The solution must not use external libraries.