Skip to content

How can I generate a maze with multiple solutions and paths? #130

Answered by john-science
ManuMassi asked this question in Q&A
Discussion options

You must be logged in to vote

Hello!

That's going to be tricky. All the maze-generating algorithms here create what are called "perfect mazes". Those are mazes with one, and only one solution. So none of these will generate you exactly what you want out-of-the-box.

BUT, you could generate a maze, using any of the maze-generating algorithms here, and then randomly remove any one wall. This will almost certainly create a loop in your maze, and thus multiple solutions.

And then you could use a maze-solving algorithm that works with loops and finds multiple solutions (say ShortestPaths).

Sounds like it should only take 10 or 20 lines of code.

If you need to know how to use mazelib, check out the API docs.

Good luck!

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ManuMassi
Comment options

Answer selected by john-science
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants