Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] Maze Generator

Author
Message
Ankillito
17
Years of Service
User Offline
Joined: 10th Dec 2006
Location: Litigious California
Posted: 2nd Oct 2008 01:56 Edited at: 2nd Oct 2008 01:57
Here's a simple maze generating program.
Algorithm:

Set a current cell
Set the count of cells visited to 1
while not all the cells have been visited,
if all adjacent cells have been visited
backtrack
else
pick a random adjacent cell
delete the wall between the two cells
make the next cell the current cell
increase the Visited counter
endif
endwhile

Hope it helps someone. I used it to generate a random maze for a map for Wesnoth. The players start in the corners and have to find each other to kill them. It should be quite fun. The attached pic is the actual level.





http://forum.thegamecreators.com/xt/xt_apollo_pic.php?i=1234759

Attachments

Login to view attachments
draknir_
17
Years of Service
User Offline
Joined: 19th Oct 2006
Location: Netherlands
Posted: 4th Oct 2008 03:24
Cool, I can definitely find a use for this since a proper maze game is something I've wanted to do for a while. Thanks!
calcyman
16
Years of Service
User Offline
Joined: 31st Aug 2007
Location: The Uncertainty Principle
Posted: 4th Oct 2008 09:44
That screenshot looks really cool - is it an RTS or something?

The optomist's right, The pessimist's right.
Ankillito
17
Years of Service
User Offline
Joined: 10th Dec 2006
Location: Litigious California
Posted: 4th Oct 2008 09:51 Edited at: 4th Oct 2008 09:52
Yeah. In case I wasn't clear, that pic is the map viewed within the real game, it is not a screen shot of my program. The Battle for Wesnoth is a free turn-based fantasy strategy game. It's quite cool, for a free turn-based game:
http://www.wesnoth.org/

Here's the screen shot from MY code: (not quite as cool...)


http://forum.thegamecreators.com/xt/xt_apollo_pic.php?i=1234759

Attachments

Login to view attachments
ozmoz
17
Years of Service
User Offline
Joined: 25th Apr 2007
Location:
Posted: 5th Oct 2008 21:56
very sweet javascript:insertSmiley('')
AndrewT
17
Years of Service
User Offline
Joined: 11th Feb 2007
Location: MI, USA
Posted: 7th Oct 2008 01:18
Very cool!

calcyman
16
Years of Service
User Offline
Joined: 31st Aug 2007
Location: The Uncertainty Principle
Posted: 8th Oct 2008 09:33
It's still interesting - it will be useful for procedurally generating maps for games, regardless of genre.

The optomist's right, The pessimist's right.
Ankillito
17
Years of Service
User Offline
Joined: 10th Dec 2006
Location: Litigious California
Posted: 8th Oct 2008 19:14
Well, kind of. The game I tried to use it for was a battle game. Because there is only one route to your enemies, it will always end with two players bottle necked and unable to move the front line. Macro strategy is completely gone because there's no way to flank or anything. I think I need a new algorithm that allows about 2 paths to and from any given point.

http://forum.thegamecreators.com/xt/xt_apollo_pic.php?i=1234759
calcyman
16
Years of Service
User Offline
Joined: 31st Aug 2007
Location: The Uncertainty Principle
Posted: 8th Oct 2008 22:27
Try searching the Internet for diffusion-limited aggregation (DLA). It's a good way of creating branching structures, and I'm sure that it's possible to develop a maze generator based on that.

The optomist's right, The pessimist's right.

Login to post a reply

Server time is: 2024-05-18 13:23:11
Your offset time is: 2024-05-18 13:23:11