Random Maze Generation

So I’m not entirely sure how the method works, but I would assume instead of making a uniform grid of objects you can randomize the placements.
Since you want it to be a maze with 90 corners I would do something like a loop that runs through the grid, and instead of spawning an object every time make it a chance to spawn.
For flowlab, I think you should make a separate object to mark where the maze is. when an object is added to the maze spawn a maze marking object in its location.
The proximity should be run by every object that isn’t in the maze yet.
I would use a number list, they are usually easier to convey data.

I think I may just make an example because it’s too much to include over text

1 Like

Ahhh, ok. Here I was assuming (hoping) you were some kind of random maze generation expert (jk). Here’s my game if you wanna see what I have so far. Level 1 is where I’m making the prims method thingy. All of the code for it is in the “Prim’s algorithm” block. The globals are sending info to and getting info from the “not in maze” blocks

3 Likes

I’m done finally, I’m not sure if this would work for your project

2 Likes

Woah, how’d you do that? Could you maybe explain what is happening in there? I’m looking at the code, but it’s kinda difficult to get a grasp on what is actually going on, especially because it loads so fast when I press play that I cant really see what parts are doing what. Mine currently takes like 30 seconds to load, lol.

Edit: By the way, thank you so much for even taking the time to make this for me! I really appreciate it. :slight_smile:

1 Like

I’ll go through it, in chronological order.
First, I spawn the starting points


The loops run through a 10x10 grid
Each instance of the loop it goes through a random number to determine if the point is spawned or not.
The equations use what iteration of the loop it is to determine the x and y position

Each time an object is spawned it increases a counter by 1.
When an object is spawned it uses the counter to assign a starting value to the point

1 Like

When it’s done spawning the random grid, it outputs how many points were spawned and selects a random value from 1 to the number output.
this random value is sent to all the points, and the point with the matching starting value is made the start.


Making it the start involves changing an object value and spawning a maze object

1 Like

Then an input sends a message to every point telling it to search. This is what happens when you press space. The points find out if they are in the maze or not with the object value.


When they aren’t in the maze yet, they use proximity and extractors put into an equation. The equation finds the x and y distance to the closest maze object, and returns either the x or y distance, whichever is larger. Then, it takes that distance, multiplies it by 1000 and adds it’s starting value. It inserts this number in a number list global.

Shortly after that, the number list global is sorted numerically so that the shortest number is first. Take note that the number in the list are (Distance * 1000) + starting value. This means that the number with the smallest distance is chosen. Then, the starting value is found with the equation A%1000. This starting value is sent to every point, and the point with the matching starting value is added to the maze

Adding a point to the maze is essentially the same thing as making it the starting point, except a connection object is also spawned. The starting value of the connection block contains the angle and distance to the nearest maze block, so that the connection object can rotate and resize to make it look like there is a path between the points.

One last thing is that when a point is told to search, and it is already part of a maze: instead of adding (distance * 1000) + starting value to the number list it uses 999999999999. This is so that when the manager searches for the smallest distance, there is no way that it will be selected.

I hope that explanation made sense. If you have any questions or want any more help I’d be happy to respond :slight_smile:

2 Likes

Wow, thanks so much for the explanation! It makes a lot of sense now, lol. I’m going to put this into my game now (assuming you’re ok with that, of course), and try to customize it a bit. I’ve had an idea. I want to try to adapt this such that it would put even more points between the existing points to connect them. Like, where it would make a path out of the “maze” blocks in the grid connecting two points instead of (or in addition to) the green “connection” thing that is currently there. How hard do you think this would be? Maybe I could like use the angles or something to try to… I really don’t know, lol.

2 Likes

I’m not completely sure what your idea is…
I’m totally fine with you copying it or taking inspiration, I’d love to see what you make
I went ahead and added a final stage to the example where it makes walls and a controllable player
I also decided to make a copy for generation that creates corner connections instead of direct connections

3 Likes

OH IT WORKS PERFECTLY!!! Thank you so much for that! This is immensely useful! You are amazing!

3 Likes

No problem, it was fun lol :slight_smile:

3 Likes

Ok, so I was testing it out (just the corner version, btw), and I made a change such that now, instead of having to press space to connect the dots, it automatically does it, which makes for much quicker and easier testing of maze generation, but I noticed that occasionally the maze ends up with certain points (or clusters of like two or three points) that are not actually connected to the rest of the maze (this happens in both my modified version and in the original, although it does not appear to happen in the one without the corners), and then (rarely) something like this happens where a large section of the maze remains unconnected.
Screenshot 2022-02-07 11.55.10 AM
I have only seen this large disconnect happen in my version, but it might also happen in yours. In my messing around, I found that increasing the chance of a point spawning (and ultimately spawning more points) leads to a higher frequency and quantity of unconnected sections of the maze. So, basically, I’m kind of just wondering what you think of this particular issue? Do you have any idea what particular parts are causing it? I have a feeling it has something to do with how it is finding the positions for the vertical and horizontal connections, but I don’t really understand the expressions in those blocks enough to be able to know for sure.

2 Likes

I have noticed this too, but I haven’t looked to much into it. all I know is that the connection is either not spawning correctly or not at all
It could either be a wrong spawning location, 0 length, or just the timing isn’t right

3 Likes

Ahhh, ok. Thank you! I figured it was probably something like this. Glad I’m not going insane, lol. Now begins the debug process, lol. I’ll let you know if I figure it out!

3 Likes

Ok, so I couldn’t quite pin down what the actual cause of the issue was, but I think I may have fixed it anyway. Basically, I reasoned that this issue is somewhat rare and inconsistent (hence not being able to find what triggers it), and as such it would be highly unlikely to happen two or more times in a row, so I simply went into the “AddToMaze” bundle in the “point” and added repeaters after each possible output from the router to make it spawn every connection twice since it doesn’t exactly hurt to have a duplicate path (since it is literally the exact same path), and if a connection did mess up and get skipped (for whatever reason) then the second path would spawn directly afterward, fixing everything. I have gone through many different maze iterations, and have not encountered the issue since, but I can’t be 100% certain whether or not I actually fixed it because I never actually found out how to trigger it. Here’s the link to the game again if you wanna see it

2 Likes

I always have fail-safes in my code in case something goes wrong. Can’t wait to see the finished product of this, it reminds me of my favorite atari game (I’m not super old, I got it for Christmas 3-4 years ago)

3 Likes