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.

23 of 83 comments (clear)

  1. Are you freaking serious? by DigitAl56K · · Score: 5, Insightful

    Have we slipped so far down the performance-orientated slide that we are impressed by *how well a dungeon generator runs on an i7 with 16GB of RAM*.

    I am genuinely curious. That is an outrageously high spec for a dungeon generator.

    1. Re:Are you freaking serious? by l0ungeb0y · · Score: 5, Funny

      Have we slipped so far down the performance-orientated slide that we are impressed by *how well a dungeon generator runs on an i7 with 16GB of RAM*.

      It's C# -- so it's likely that's the minimum requirements for a compiled .NET App to run

    2. Re:Are you freaking serious? by lgw · · Score: 2

      There are still plenty of people interested in getting stuff to run in 256-512 MB with a 700 MHz ARM. I think about half the tendency for code bloat in the past 15 years has been the decline of cheap hobby PCs - a vacuum that has now been filled. Still seems like a lot to me, but it does at least impose a little restraint and interest in optimization.

      (The other half is of course managed languages, but really slimming down C# to work on a RP doesn't seem impractical - just something that MS hasn't had a reason to focus on.)

      --
      Socialism: a lie told by totalitarians and believed by fools.
    3. Re:Are you freaking serious? by PPH · · Score: 4, Funny

      C#/.NET makes great dungeons. Resources go in but can't get out.

      --
      Have gnu, will travel.
    4. Re:Are you freaking serious? by Anonymous Coward · · Score: 5, Interesting

      I have been running C# ASP.NET on Raspbian Apache/ModMono for a solid 3 years. No problems.

    5. Re: Are you freaking serious? by DigitAl56K · · Score: 4, Funny

      How's the systemd C# port coming?

      You'll need to be more specific, are we talking about systemd running in C#, systemd running C# code, or the port of systemd in C# that runs C#?

    6. Re: Are you freaking serious? by sconeu · · Score: 3, Insightful

      He's talking about the systemd module that *compiles C#.

      --
      General Relativity: Space-time tells matter where to go; Matter tells space-time what shape to be.
    7. Re:Are you freaking serious? by fourbadgers · · Score: 2

      I can't vote this post any higher than 5 so I'll have to reply to it and voice my agreement. "anything" should be able to run on a i7 with 16gb of ram.

    8. 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.

    9. Re: Are you freaking serious? by Minwee · · Score: 2

      Writing the compiler was the easy part. The problem is that it wants to keep recompiling my code every time I press 'Enter'.

    10. Re: Are you freaking serious? by Hadlock · · Score: 2

      Jumping on this thread, if you want a dungeon generatore, check out the Libtcod library, it's been ported to Python, C++, C#, and very recently TypeScript (i.e. Javascript#)
       
        http://roguecentral.org/doryen/
        https://github.com/jice-nospam/yendor.ts
       
      Here's an example from 2011: https://www.youtube.com/watch?v=DZkDOx4W3zs

      --
      moox. for a new generation.
    11. Re:Are you freaking serious? by angel'o'sphere · · Score: 2

      It is a big dungeon, mate! A really big dungeon! You know, with torture chambers, torture mistresses and such. Lots of moldy bread and stinking water. Imagine the whimpering and sobbing. Water drops down from the ceiling and flows down at the walls. The stink of excrements and rotting corpses. Then all the guards with warts on their faces, sometimes on the nose, sometimes on the cheek, sometimes on the forehead. All that needs computing power! Especially the stink and the warts, obviously.

      However I'm surprised that you can even do that without touching the bare iron, would not C++ be better suited? Or even C with the occasional throwing in of assembly? I mean: the warts would likely benefit from some fine tuned assembly, no?

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
  2. Alternate Link by Anonymous Coward · · Score: 5, Funny
  3. Amazing performance ! by alexhs · · Score: 3, Insightful

    It's amazing just how fast it runs on a five-year-old i7 950 PC with 16GB of RAM.

    Yep, almost as fast as the original's code on a i386 with 4MB of RAM. Impressive.

    --
    I have discovered a truly marvelous proof of killer sig, which this margin is too narrow to contain.
  4. So someone else invented NetHack, goodie. by Anonymous Coward · · Score: 4, Insightful

    NetHack has had procedural dungeon generation with available source for .... gosh a long time.

    1. Re:So someone else invented NetHack, goodie. by Windwraith · · Score: 2

      And the original Rogue is even older than that, so yeah, why is this news?

    2. Re:So someone else invented NetHack, goodie. by Coren22 · · Score: 2

      Nethack confirms it.

      --
      APK likes to ask for responses to the same things over and over. Maybe he just likes the responses?
  5. Oh Goodie by Anonymous Coward · · Score: 2, Insightful

    Another shitty dungeon generator.

    Why not post this in /r/cartographersguild or something?

    There are already lots of shitty dungeon generators, you're probably not doing anything useful like using features that are in sourcebooks, and dungeon building is almost certainly something you should be doing by hand anyway. Even if your party is a bunch of mindless murderhobos. Good dungeons make enough of a difference that people will actually pay real money for them. If you want story on top of an interesting tactical scenario then you have to do it yourself, and this is not likely to be a good place to start. You should start with a line diagram connecting *encounters* with each other (straight lines, branches, loops), and then come up with the layout. Doing it the other way around makes for shitty dungeons. There are books and papers on this topic that would be much more useful.

    And another thing, as long as I'm ranting: don't use traps. They slow the game down and decrease player resources without actually giving them agency. They serve no narrative purpose. If you must have traps, have them [a] sound alarms or otherwise summon foes, or [b] make it a risk / reward situation: make their choices interesting. If, given complete knowledge of a situation, you would always want to choose one action, you're not being given a real choice. Choosing to avoid a trap isn't an interesting choice. Choosing to walk into a trap because the danger is worth the shiny thing you might get out of it is far more interesting. See also FPS map design, good example would be Unreal Tournament's DM-Pressure, where there's a powerup inside a room, and a button other players can hit to kill anyone in there. Risk vs reward. There's actually quite a bit about FPS map design that's applicable to PnP RPGs.

    tl;dr
    This is not a way to generate maps that people will want to play. If you have to use a generator, there are better options. If you want to learn about how to make good maps, there are better resources. If you want to pretend that something you wrote decades ago is full of important lessons for other people, fuck off.

  6. Amazing indeed by jones_supa · · Score: 2

    It's amazing just how fast it runs on a five-year-old i7 950 PC with 16GB of RAM.

    Yeah, it's five year old, but even today a very fast CPU. Has a CPUMark of 5600. High TDP of course.

    1. Re:Amazing indeed by LWATCDR · · Score: 2

      I thought the same thing.
      Computers has been very fast for a while now. Only things like transcoding and some gaming really push CPUs for the "average home user".

      --
      See my blog http://ilovecookes.blogspot.com/ for light hearted technical information.
  7. 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.

  8. Re:Okay... by jandrese · · Score: 2

    His comment about running it on a high power i7 with 16GB of RAM might at least make sense then. That's what you need to build a medium sized DF map with 1000 years of history baked in.

    --

    I read the internet for the articles.
  9. Re:After 15 years by drinkypoo · · Score: 2

    Karma has been kapped at 50 for years now, unless it was uncapped along the way someplace

    --
    "You're right," Fisheye says. "I should have set it on 'whip' or 'chop.'"