Omnimaga

General Discussion => Other Discussions => Miscellaneous => Topic started by: Scipi on August 04, 2011, 09:09:51 pm

Title: Maze algorithm help
Post by: Scipi on August 04, 2011, 09:09:51 pm
I am working on a small maze game and I am hitting a roadblock in generating a random maze. I'm trying to implement the depth first algorithm but I'm unsure how to even start. Can someone come up with some code or help me with the overall programming logic to generate the maze?

Thanks.
Title: Re: Maze algorithm help
Post by: calcdude84se on August 04, 2011, 09:22:03 pm
Here's a page full of maze generation algorithms: http://www.astrolog.org/labyrnth/algrithm.htm (http://www.astrolog.org/labyrnth/algrithm.htm)
Eller's algorithm is cool because it only needs to store data for one row of the maze.
Edit: If you're any good at reading BASIC code, I do have a program that implements Eller's algorithm. Lemme find its topic...
Edit 2: Found it. http://ourl.ca/8028 (http://ourl.ca/8028)
Title: Re: Maze algorithm help
Post by: Scipi on August 04, 2011, 09:43:04 pm
I tried looking at you code, but I couldn't figure it out. I'm pretty bad at reading code sometimes. :P

What was the general logic you used in that program to actually generate the maze? I looked at the site and I can't quite figure out how to implement it in a program. :(
Title: Re: Maze algorithm help
Post by: calcdude84se on August 04, 2011, 10:35:17 pm
Nah, it'd take me a bit too to remember how it works :P
As for the general logic:
Notes:
Title: Re: Maze algorithm help
Post by: Scipi on August 04, 2011, 10:42:22 pm
calcdude, you are a god. I just went on a rant on how there's no simple, easy to grasp explanation on how to implement it. Much less easy to follow source code. (Everything's optimized beyond all comprehension) :P

With this I can finally get this thing coded. XD
Title: Re: Maze algorithm help
Post by: calcdude84se on August 04, 2011, 10:45:29 pm
And, to clarify further, a set of connected cells is one whose cells' values are all the same. (Edit: except the first time it's mentioned, where it actually means its literal meaning. You could have a counter that you increment every time you don't connect to the cell on the left in the first row to initially fill array OLD.)
And the code isn't very optimized; it's just TI-BASIC. I have never found a way to make TI-BASIC code easy to read for more complicated things.
Glad you like it :). Maybe I should start writing tutorials...
Title: Re: Maze algorithm help
Post by: Scipi on August 04, 2011, 11:54:53 pm
Ok, so I started and so far I have the code to make the first row

http://pastebin.com/vH1VdNyD (http://pastebin.com/vH1VdNyD)

Up next would be to start making the next rows correct?

I'm thinking to make the next rows I would effectively do a pointer switch between Old and New, so basically

Code: [Select]
myfunc([address of Old], [address of New])
{
    (Pick a cell from a set in Old and copy it to New)
    (Remove Wall between them)
    For(i = 1; Width; i++)
    {
    if(!part of a set)
    {
        Random(0, 1)
        If (1)
        {
            (Copy cell from Old to New)
            (Remove Wall)
        }
        else
        {
            (Make new cell here)
            if(rand(0,1))
                (copy cell from left and remove wall)
        }
    }
}

myfunc(New, Old)//Notice I switched old and new so that in the func, New becomes Old and vice versa




Would that pretty much do it?
Title: Re: Maze algorithm help
Post by: calcdude84se on August 06, 2011, 08:19:36 pm
I'll need some time to learn a bit of C++ and look over what you've written.
Meanwhile, you could just continue yourself and see if you can get it work :)
Title: Re: Maze algorithm help
Post by: Scipi on August 06, 2011, 10:16:59 pm
That's what I'm so far doing. I've got to the point of making random drop downs from each set and making sure each set has at least one. Next up is to make the empty cells their own set and randomly connect them to existing sets.