Slashdot Mirror


Building a Procedural Dungeon Generator In C#

Nerval's Lobster writes Procedural dungeon generation is a fun exercise for programmers. Despite the crude interface, such games continue to spark interest. A quarter century ago, David Bolton wrote a dungeon generator in procedural Pascal; now he's taken that old code and converted it to C#. It's amazing just how fast it runs on a five-year-old i7 950 PC with 16GB of RAM. If you want to follow along, you can find his code for the project on SourceForge. The first part of the program generates the rooms in a multilevel dungeon. Each level is based on a 150 x 150 grid and can have up to 40 rooms. Rather than just render boring old rectangular rooms, there are also circular rooms. "There are a couple of places where corridor placement could have been optimized better," Bolton wrote about his experiment. "However, the dungeon generation is still very fast, and could provide a good programming example for anyone exploring what C# can do." For C# beginners, this could represent a solid exercise.

2 of 83 comments (clear)

  1. Re:Are you freaking serious? by colenski · · Score: 4, Informative

    I don't get this submission. I wrote the same thing in 1982 on a TI-99/4A with 16kb RAM and a 3MHz 16 bit chip. It loaded from a cassette deck using an analog stream from the tape. It displayed on my TV. It was written in BASIC. It sucked.

    But it *worked* fine, I mean it drew the map in well under 10 seconds, printed it, then used the edge dots of one side as the seed for the next section of the dungeon. Isn't that what this is, and why do we even need an ARM for this, you should be able to get decent performance from a 4004!

    This was my first real piece of software, and it worked on the first try (by that I mean I wrote it and bugfixed it, and...it worked). I was 13. You millennials or whatever you call yourselves should be running rings around me - who needs multiple cores or C# for this?? Do it in Minecraft, then I'll be impressed.

  2. What? by gabereiser · · Score: 4, Informative

    I really don't understand why this article is a thing. For 1, it's a really shitty way to generate dungeons as there are vastly superior ways of doing it: cellular automata http://www.futuredatalab.com/p... for example can product cave like dungeons, regular rectangular dungeons, etc and not just something made with ASCII that needs to then be converted. I've even seen KDtree's drawn out to represent rooms and such for muds. This article fails on a multitude of fronts. First being the DICE ad tracker embedded in the link to the article. Second, being the fact that he is "impressed" with how fast it runs on a Core-i7. Third, the use of SourceForge, where projects go to die. And finally, the fact that the article says it's geared towards beginners, teaching them bad coding practices and the like with the shitty code that's on sourceforge.