Random Maze Generation

Hello, there! I wish to make a game that includes (or, rather, is centered around) a maze. I could design the maze by hand, but that is tedious, and gets quite repetitive, especially because my plans may include making the maze absolutely gigantic. I would also just like the game to be infinitely replayable, something that a little bit of randomization could easily achieve. So my question is, does anyone know how I would go about randomly generating a maze? I tried simply googling maze generation, hoping I could use a tactic there, and found this Wikipedia article listing a whole bunch of different methods, but I donā€™t know how I could possibly implement those in flowlab. Any help is appreciated!

4 Likes

Start small. I would not make a massive rng maze, as that is extremely ambitious, and will eat at computing power.
Instead, I would make your game (I assume itā€™s a rougelike) consist of smaller levels that are linked by a door, staircase, etc. These can (and should be) randomized.
There are several ways that you could randomize your levels, but the simplest one I could find is this: spawn one room, and have that room spawn a hallway/room/etc next to it (this process should repeat itself until the desired amount of rooms are spawned). These rooms and hallways should be presets, and shouldnā€™t be too complicated. After x amount of these rooms and hallways are spawned, an option should become available to spawn nothing. Then, after y amount of these rooms are spawned, you should completely disable additional room spawning.
I am not sure how you would make the rooms not spawn on top of each other, but raycasts are probably your best option.

3 Likes

Ahhh, ok. You make a really good point there, lol. My original idea was to make something kinda like the Maze Runner (hence, the ā€œabsolutely giganticā€ part), but that probably would absolutely destroy even the beefiest of PCs, and since Iā€™m making it on a Chromebookā€¦ That would not end well, lol. So, lets say I wanted to make a series of smaller randomly generated mazes, how would I do this?

3 Likes

I elaborated on how you would do this with an extremely long edit. Itā€™s the massive paragraph at the bottom.

2 Likes

I think thereā€™s an example on random path generation

3 Likes

I think a good way would be primā€™s algorithm. Iā€™ll use [] brackets to show how to do it flowlab
Kinda goes like this:

  1. Get a bunch of points [make a bunch of objects, assign a unique value to each]
  2. Make one point the start and ā€œput it in the mazeā€ [select a random value and put it in a list, spawn an object to mark it as part of the maze]
  3. Find the closest point that isnā€™t in the maze yet [Each object can use proximity to find the distance, then put that distance + its assigned value into a list, then organize the list, then get the lowest numbers id]
  4. Make that closest object part of the maze and connect it to the closest part of the maze [Send the index through a message, the object with that index can get the position of the closest part of the maze using proximity, use trig to make a connection]
  5. repeat 3 and 4 until all the points are complete

let me know if anything is confusing
For the way to spawn all the objects you could use a repeater the spawn everything in a grid

4 Likes

Or binary tree maybe ?

Or this, both unfinished concept studies.

3 Likes

This is what I saw, just couldnā€™t remember where

2 Likes

Ok, so Iā€™m looking at these, and I really like the idea of doing it like that (primarily the ā€œDungeon Generatorā€ one), but Iā€™m looking at the code to try and figure it out so I can customize it, and I donā€™t really understand any of it. Could you maybe explain what is happening in there? Especially, where would I need to go to edit the rooms themselves to spawn multiple different types of rooms, and how would I store a room to be generated?

1 Like

How, exactly, should I assign a unique value to each one? They should all be the same object type, right? Just use different object names? Would that even work?

2 Likes

use another object to spawn them all in, assign a starting value to each one
You could use a repeater that increases a value each time it spawns

1 Like

Ok, so wait a sec, I can spawn them in using a spawn block, but how do I then give them each a different starting value? The spawn block only has inputs for x, y, and spawn

2 Likes

the starting value is the value used in the spawn input

2 Likes

For example, the starting value here would be 3
image
And then in the object you spawned you can use an extractor to get the starting value
image

3 Likes

Ohhhh, ok. That makes sense now. I didnā€™t realize that was a thing, lol

3 Likes

yeah I didnā€™t know either until someone told me I should use it TT

3 Likes

In ā€˜Corporate Goblinsā€™ we use bundles that spawn each room type (1x1, 2x2, 3x3, etc.)
So each bundle will be called with the x/y coordinates where we want to spawn a new room.
Then from the bundle we spawn all the room elements like walls, doors, etc.
On top of that randomized content will be spawned, furniture, weapons and so on.

Since we canā€™t group objects (yet) this is the only work around I am aware of.
Makes sense?

That info could be saved in a list. Like room ID(type) and x/y position if need be.

4 Likes

And as mentioned, both examples are just concept tinkers, buggy as hell.
Wouldnā€™t do it like this again.
From my experience with SeedBot the whole Binary Tree Generator (or any other by that matter), Iā€™d probably wrap in one mega expression now that I know how it works.

3 Likes

Ok, so I got it to autofill all of the cells, assign them values, and then pick a random one to be the start and make it part of the maze, but step 3 confuses me a little bit. What objects, exactly, should use the proximity, and what should they be looking for, and how far should the proximity be? Also, another question I had: looking through the different steps here, would this system end up making all of the cells part of the maze? If it always finds the closest point that isnā€™t in the maze yet, what stops it from filling all of the cells with maze?

Edit: I would also like to know what kind of list I should be using to store these values and how I should be doing that. Iā€™ve never actually used the list behavior before

1 Like

Yikes, that sounds complicated and time-consuming, lol. Do you mean that I would have to put in a spawn block to manually spawn every single object in whatever room I was making? I mean, I could maybe probably do this, but idk. I wish there was an easier way, lol.

2 Likes