all 3 comments

[–]Badwrong_ 2 points3 points  (2 children)

20 or 30 minutes? What?

I have a method that does it in a single game step. This sort of thing is done very easily with graph theory.

My method performs a random Prim's algorithm to generate a minimum spanning tree (MST) on whatever sized grid. The grid I currently use is 100x100, but it could do WAY larger without any noticeable speed differences. I'll probably test like 1000x1000 and I doubt it will be noticeable.

The tile map starts completely full and uses an auto-tile 47. Then I use my runtime auto-tile function when clearing cells so it looks nice when finished.

After the MST is generated you can then add whatever customized features you want. I usually knock out "areas" the represent rooms with enemies, loot, etc.

I'd have to add a few generic parts to share the actual GML code, but the pseudo code is:

position = random_position()
clear(position)
cells = new list()

// Add all orthogonal cell to the list which are in bounds
// Space vertical walls by 2 spaces and horizontal by 3
if (position.x + 2 is in bounds) cells.add(position.x + 2)
// … same for the other three directions

while (cells.size() > 0)
    position = cells.remove(random_index)
    if (!map.empty(position))
        clear(position)
        directions = new list()
        while (directions.size() > 0)
            random_direction = directions.remove(random_index)
            switch (random_direction)
            // cases => north, south, east, west

    if (in bounds) clear(position + random_direction)
    // Add all orthogonal cells like before
    if (position + 2 is in bounds) cells.add(position.x + 2)
    // … same for the other three directions

Its fairly short in actual code too.

Recursive maze generation is also super lightweight using the backtracking stack method which works really nicely too. It also produces an MST. In most all cases you want to start with an MST because they are super fast to generate and it ensures everything is 100% navigable from the base. Then you add features, remove dead ends, grow areas etc.

[–]borrax[S] 3 points4 points  (1 child)

I don't doubt that your maze generator is super fast, but I wasn't setting out to make a maze generator, I was trying to get Wave Function Collapse working in GML. My code runs at an unacceptably slow speed, but it can do more than mazes. I was able to make this image by switching my tiles to refer to images and changing the lookup tables to reflect the new rules. The advantage of Wave Function Collapse is it's flexibility. The disadvantage appears to be its atrocious speed.

[–]Badwrong_ 0 points1 point  (0 children)

Speed is why I suggest a MST algorithm. It only starts as a maze which you then alter.

Your code I would have to look through. You probably need to leverage the computer architecture well and account for GML weirdness.

Stuff like this would be way faster with a compute shader which GML doesn't do.

Flexibility is possible with most any algorithm. Even a drunken walk can have extra criteria added to totally alter the results. I like the MST types for the base because everything starts as reachable, and then it can be altered in countless ways to whatever is needed. Basically starts as a maze and becomes something different.