So, I found this page which talks about how maps in the game Berzerk were generated. They look like this:


Basically, you start with an open map, with 8 pillars (O=pillar, X=wall)

Code:
XXXXXXXXX   XXXXXXXXX
X                   X
X                   X
X   O   O   O   O   X


X   O   O   O   O   X
X                   X
X                   X
XXXXXXXXX   XXXXXXXXX


Then for each pillar, we pick a random direction to extend a wall toward:

Code:
XXXXXXXXX   XXXXXXXXX
X   ^           ^   X
X   |           |   X
X   O<--O   O-->O   X
    ^       ^
    |       |
X   O   O   O   O   X
X       |       |   X
X       v       v   X
XXXXXXXXX   XXXXXXXXX


I thought this was neat and wanted to make my own program to do so, and so I did:

I made it pretty general, so you can change the dimensions of the map and the wall to get something like this:

or this:

Though the drawing part and the actual maze generation part are all separated out. You can download it from:
http://merthsoft.com/Maze.exe (code)

Maze.cs has the actual room generation code. It's as simple as one might expect: pass in a seed, use that to seed the random generator, for each pillar generate a random direction. When creating the Maze object you specify the width and the height (there's no reason this couldn't be per-room, I guess), as well as the number of possible directions. In Main.cs I do the bulk of the work for rendering the map. Direction.cs is just a simple enum for keeping me sane.

Which rooms lead where I decided to leave out of the Maze object in favor of putting it in the implementation. I guess it could make sense in either place, but that's how I decided to do it.

Play around with it if you want. The code is free to do whatever you want with it, I don't care.

Here's a big maze:
Cool! I saw that explanation of the Bezerk maps floating around, but it didn't have enough pretty pictures for my taste. Yours hit the spot.
Nice work & thanks for sharing - it reminds me of this :
There was a game for the VIC20 / C64 in the 80s called Munch Maze which was basically a PAC-MAN clone. I got it from a magazine and the interesting point is, that it was coded all in BASIC. This included the random Maze generation algorithm complete graphics rendering and game play controls all under 3.5kB. I recall it was pretty cool but it was hard to pick apart how the maze was calculated randomly each time but still remained valid - wish I had kept the code...
Great job, Merthsoft, and bonus points for the basis in a classic game. Are you planning to expand this into a game of some sort, or was the point mostly exploring the algorithm?
Munch Maze, huh? I have a TI-99/4A game called Munch Man, it is a Pac Man clone too. I wondered if it was related.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement