Successful random maze generator. EDIT now a simple game.

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
forestwolf42
Prole
Posts: 24
Joined: Tue Dec 20, 2011 5:18 pm

Successful random maze generator. EDIT now a simple game.

Post by forestwolf42 »

EDIT This is now a simply game, arrowkeys to move, space on the solid red block to complete the maze, once you finish the maze it will generate a slightly larger one, this could theoretically go on forever but you'd run out of screen first.

Thanks to Jasoco and Merekkpie for helping me out on this, but I wanted to let the world know that it's finally working, although it is slow, and I will warn you it doesn't like to close itself for some reason, but regardless, it works.

It works by making a large area of walls, walls are 1's in the code, it then makes 0's 0's are not ground, but they will be, I guess they're unmarked ground. When it encounters a dead end, it goes back along the path of 0's turning them into 2's (proper ground) until it finds a branch to create more 0's off of.

Anyway, It's not the best code in the world but it was my first coding project, I think I'll leave random generation projects for awhile and make a Light Cycle's game or something now.

Once again, thanks to Jasoco and Merekkpie for being patient with me in the forums.

Note, you have to use the q key to quite, if you're using lua 8 it probably won't work, this was written in 7.2
Attachments
mazeGame.love
Working game
(1.86 KiB) Downloaded 304 times
Last edited by forestwolf42 on Thu Feb 16, 2012 8:16 pm, edited 2 times in total.
User avatar
Ellohir
Party member
Posts: 235
Joined: Sat Oct 22, 2011 11:12 pm

Re: Successful random maze generator.

Post by Ellohir »

Looks cool, in just a few seconds I understood what the code was "thinking" to do the maze. Great job, I love this kind of "animation calculation" thingies.

Though, at the end of the first run the program freezes and I had to kill it. And didn't got it to work again. Weird. Let's see if it happens to anybody else.
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: Successful random maze generator.

Post by coffee »

Insteresting but maybe something is pushing too much for the machine and doing some loop. When working your app here in OSX calls the distressing rainbow cursor. Also when it's done I need to force quit it.
User avatar
forestwolf42
Prole
Posts: 24
Joined: Tue Dec 20, 2011 5:18 pm

Re: Successful random maze generator.

Post by forestwolf42 »

It does loop and continue to search for possibilities after there aren't any, I'll fix this.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Successful random maze generator.

Post by Jasoco »

Interesting. I'm a fan of Depth-first Search, but I don't know what to call yours. The back-tracking is interesting. I prefer to create the path first, then select a random cell that has an empty neighbor and jump to it, then loop until all cells are filled or the quota is reached. Yours seems to backtrack along the path it just came until it finds an empty cell. How long would this take if it were all in one loop without having to draw its progress?
User avatar
forestwolf42
Prole
Posts: 24
Joined: Tue Dec 20, 2011 5:18 pm

Re: Successful random maze generator.

Post by forestwolf42 »

The idea was to be a depth first search maze maker, it just finds the cells systematically as opposed to randomly.

Well of all the things I'm having trouble getting the program to recognize when it finishes making a map. I guess it's probably code gremlin hunting time again. But when I do, I will see how fast it is without constant drawing.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Successful random maze generator.

Post by Jasoco »

I basically made a "time out" limit where it would only run my path drawing routine a certain number of times where it selects the random cell and draws it.

I think what you could do is:
A) Set a variable to the amount of cells available (Width x Height of map)
B) Whenever you set a cell to "Taken", you decrement the variable. (Only when it's marked as pathed, not when it's traversed again)
C) When the variable reaches 0, you're done.
User avatar
forestwolf42
Prole
Posts: 24
Joined: Tue Dec 20, 2011 5:18 pm

Re: Successful random maze generator.

Post by forestwolf42 »

See, I had that variable, but then I deleted it because I didn't think I needed it. I feel very foolish now.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Successful random maze generator.

Post by Robin »

Can't you just check if you have backtracked until the beginning? Because if the starting point is "back-tracked" or whatever, it means that the whole maze is filled, right?
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests