T
T
Tera Incognita2021-04-08 23:00:58
Algorithms
Tera Incognita, 2021-04-08 23:00:58

How to generate a maze with walls so that there is always a path in this maze?

A simple maze is generated from tiles.
606f5f9c92af3928654573.png

The generation of the labyrinth with walls has differences. There are theoretically two solutions, but which are problematic to apply in practice.
The programming language is not important.
The decision itself is important ....... The task is to build a generated labyrinth with walls where there is always an entrance and exit ...
You have tiles vertical and perpendicular.
606f60cff23b5407525598.jpeg

the problem is that you will have a dead end ....
How to avoid this and ensure the rotation of the tile?

We need a theoretical solution that is implemented in software, with a step-by-step explanation of the theory

Answer the question

In order to leave comments, you need to log in

4 answer(s)
G
Griboks, 2021-04-08
@Lunali

There is a fairly simple and understandable algorithm:
1) We get to the starting point adjacent to the entrance.
2) We generate a random tile (r, -, +, m, ...) in such a way that it has an entrance connected and at least one exit is not blocked (by walls of the labyrinth and other tiles).
3) If there is no such exit, we generate a new tile so that there is one. If still not, then go to step 5.
4) Move to the exit of the current tile. Now the empty space is our current point.
5) We repeat until we hit a dead end, i.e. there will be no free exit from the current tile.
6) We go back to the first branch and repeat the algorithm.
7) If again there are dead ends in all branches, then we return even further back.
8) If we nevertheless returned to the entrance to the labyrinth, then we erase everything and start the algorithm over again.

C
cicatrix, 2021-04-09
@cicatrix

At the time, it was pretty straight forward. On the maze, I first generated a path from point A to point B randomly and marked these cells as checkpoints. And only then around randomly generated the rest of the maze.

A
Armenian Radio, 2021-04-08
@gbg

There are many such articles.

A
alexbprofit, 2021-04-26
@alexbprofit

This is a task, not a question.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question