Best logic to create a (true) random maze

I tried to make a little simple game to test my logic, and this is a simple maze, it is ugly and still juicy.

The engine works very well, given that the labyrinth already exists (matrix), it may even be nice, but I'm not going to draw a bunch of cards that can set values ​​in 400 (20x20) matrix fields. not funny.

Then I created a function for randomization, setting a floor / wall for each field, and (I expected) not every card is a winning one. then I made another function that checks if the cards are playable (gets two points and checks if there is a valid path between them, then I just pass the beginning and the end. Pretty elegant) and it worked.

If you haven’t noticed this, this is a VERY dumb way to create my random maze for the following reasons:

1 - It may seem very easy (giant islands of the floor or a bunch of walls together, creating only one, extremely visible path, creating a crazy (albeit real) maze
2 - This is potentially the fastest way to create the perfect random maze EVER, but at the same time it is potentially also the slowest, until ... endless. This difference is noticed more when I set the grid to 30x30 or more (when something is not crowded)
3 - He is dumb and insults the logic itself.

In my defense, I did not plan to do this from the very beginning, as described, one thing led to another.

So, I started thinking about how to make a beautiful (full path, difficult and winning) maze, then I thought about how to make small small (let them say) 5x5 blocks with predefined inputs and put them together in a way that suits it , but this will contradict my true random desire, as well as my unwillingness to draw it by hand.

Then I thought of a function to create a random path, ran it once to the end, and ran it several times somewhere near the end, and some transitions and stuff, some created dead ends that seemed better to me, but I just couldn’t imagine imagine that he creates a decent maze.

You can check what I have done so far in this link.

Note. I have no intention of harming anyone on the PC. First, to open it, comment here, saying that it is safe. - Done (thanks, Jonno_FTW)
If you still do not trust him, use a virtual machine.

OBS: I know that this is not the best way to develop anything. I have to get a decent game engine, bla bla bla, it was some kind of challenge for me.

+4
source share
7 answers

I made a generation of mazes. You do not want to post material randomly and check. Instead, you generate it from the starting point.

Select the starting point, move it in a random direction. Have a random probability of choosing a new direction. Never move into a busy square, if you come across one, the current end ends. If the current trail ends, select the square that you have already visited, and select a new direction and take a random walk, as you did for the first. Repeat until the maze is as complete as you want.

The likelihood of a change in direction should be an input parameter, as this is of great importance. Please note: if you are creating a 3D maze, the probability of vertical rotation should be much lower than the chances of horizontal movement.

+4
source

Here's an expanded labyrinth website: http://www.astrolog.org/labyrnth/algrithm.htm

Explains what types of labyrinths exist, processes generation algorithms and solution algorithms, has many interesting shots.

+4
source

Check out the source code in my Roguelike game, Tirana:

Code for Dungeon.java

There are many different map generation methods used to create different types of levels. But the simplest template is this:

  • Start with a blank card.
  • Create a single random room / open space on the map
  • Randomly select a tile on the edge of an open area.
  • An attempt to "develop" a corridor or room by chance from this space (if this does not fit, do nothing)
  • Go back to step 3 as many times as you need to create a decent maze
  • Finally, make a passage over the entire map and convert and leave an empty space on the walls.

Here is a screenshot of the type you are getting (look at the minimap from the maze structure):

Tyrant Screenshot http://www.freeimagehosting.net/uploads/af45502c9c.png

+3
source

Your question makes me think about XScreensaver Maze . Take a look at the screenshots to make sure that this is the desired effect.

It looks like he took the maze generation algorithm from Wikipedia.

+2
source

Wikipedia has an excellent article on Maze Generation Algorithms

+2
source

How you create a random maze will depend on how you want it to look. If you are creating something for a multitude of dead ends, you can simply “randomly” track the path from the start point to the end point, and then randomly fill in the empty spaces, essentially cutting the path out of a solid block of material. For instance. Imagine you have a stone tablet. The first step is to cut out the path of "decision." Then you go in and do all the dead ends.

If you want something more “playful” than a “puzzle,” then creating a piece of tile fragments that fit together in different ways is probably the way to go. How Diablo games did this, as far as I can tell; a series of predefined "sets" and rules on how they fit together. You marked the four sides of the block with things such as “three open spaces, followed by two closed spaces,” and then, if the other part also contains a corresponding description, you can collect them.

After that, all you have to do is figure out how you can consistently perform "random" behavior.

+1
source

In fact, the trick Al Lowe used for one of his Larry leisure games (LSL 3, I believe) can be useful.

Basically, he made a maze of bamboo forest, which the player had to move. However, instead of creating a separate “square” labyrinth for each screen, he simply “turned over” one screen that he had already created and made dead ends, blocking the various inputs with the same “bamboo wall” graphic.

Perhaps you could do the same: the generator cuts out the actual maze, and then tell it to place deadlock blocks along some paths. This ensures that there is always at least one valid open path to the finish line, as well as preventing players from passing through the super-simple layout.

It will also make the 30x30 maze more workable, as the computer does not need to check every square grid of 900 square squares for accuracy.

+1
source

Source: https://habr.com/ru/post/1314096/


All Articles