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
Successful random maze generator. EDIT now a simple game.
- forestwolf42
- Prole
- Posts: 24
- Joined: Tue Dec 20, 2011 5:18 pm
Successful random maze generator. EDIT now a simple game.
- 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.
Re: Successful random maze generator.
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.
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.
Re: Successful random maze generator.
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.
- forestwolf42
- Prole
- Posts: 24
- Joined: Tue Dec 20, 2011 5:18 pm
Re: Successful random maze generator.
It does loop and continue to search for possibilities after there aren't any, I'll fix this.
- Jasoco
- Inner party member
- Posts: 3725
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Successful random maze generator.
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?
- forestwolf42
- Prole
- Posts: 24
- Joined: Tue Dec 20, 2011 5:18 pm
Re: Successful random maze generator.
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.
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.
- Jasoco
- Inner party member
- Posts: 3725
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Successful random maze generator.
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.
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.
- forestwolf42
- Prole
- Posts: 24
- Joined: Tue Dec 20, 2011 5:18 pm
Re: Successful random maze generator.
See, I had that variable, but then I deleted it because I didn't think I needed it. I feel very foolish now.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Successful random maze generator.
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.
- Jasoco
- Inner party member
- Posts: 3725
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Successful random maze generator.
That would work too.
Who is online
Users browsing this forum: No registered users and 5 guests