Procedural Dungeon Generation Algorithm 198 points by ingve on Sept 4, 2015 | hide | past | web | favorite | 47 comments

 If anyone's interested, there is a Reddit post explaining this and an interactive demo from 2 years ago:https://www.reddit.com/r/gamedev/comments/1dlwc4/procedural_...
 More generally I would also recommend: https://www.reddit.com/r/roguelikedev
 That's a great resource! Thanks :)
 http://tinykeep.com/dungen/ _was_ the source of the figures in the article, AFAIK.
 to me they look slightly different, both in animation (because of underlying algorithmic differences) and graphics (space inside rooms is black in dungen, blue in TFA).But maybe it's just tweaks, I don't know.
 Here's a link to the original dungeon generation demo that Phi Dinh posted using this algorithm: http://tinykeep.com/dungen/ (Flash required).He kept an interesting blog about the development of Tiny Keep and added other posts about improvements to the generation mechanics for the dungeons, including this nifty one about generating locked areas that Ben Jones worked on: http://blog.tinykeep.com/2013/09/just-sneaky-quick-update-fr...
 I really like the idea to just use a physics engine as a means of randomizing the layout. Smart, succinct, and easy to implement.
 I delighted in this article because of its opinions about what is easy and what is hard. Physics engine: easy; of course you have one; everyone has a physics engine. Graph data structure & algos: suggests a few places to find one.As an older programmer who is in the midst of retooling, I would assume the opposite: graphs easy, physics hard. But that's what retooling seems to be all about -- finding the new "easy" and learning it.
 A physics system good enough to support this is probably ~200loc. Probably less if you cut out everything extraneous. All it is is AABB collision detection+resolution, and then some update code.I think the graph + graph algos would be trickier most of the time, but that could just be since I've written the above code many, many times.
 I've been working on an algorithm to make more playable dungeons with included puzzles (e.g. locked door/key quests etc.). The math is there to ensure everything is solvable and relatively interesting (you're guaranteed to run into a puzzle before you find all the elements you need to solve it, for instance) but I got bored when it came time to make an example game to illustrate how it works. I'll pick that back up at some point...
 Ever play Yoda Stories or Indiana Jones Desktop Adventures?They do something like that, but with self-contained tiles that are randomly arranged, with some variation in e.g. key/item placement.
 Brogue does this, although none of its puzzles are strictly required to progress, they are guaranteed to be solvable.Highly recommend brogue for anybody even tangentially interested in traditional roguelikes. Most interesting RL game design in years and the game is absolutely gorgeous, despite being glyph-based (no tiles). I'm on mobile or else I'd link.
 Do you have the source up somewhere?
 One of the best maze generators I've ever seen was in the ZX Spectrum (Timex in the US) game of Steve Jackson's Warlock of Firetop Mountain[1]. It's brilliant, coming up with a maze full of rooms and doors, with no islands, and relatively well placed monsters and items. And all in 48K of ram. Despite browsing the source code a couple of times I've never figured out how it actually worked.
 I've seen algorithms that produce results similar to this before, and I find them lacking in any sort of feeling of purposeful design.Dungeons are (in theory) built by intelligent people for a reason. There needs to be distinct working, eating, socializing, farming areas. There needs to be wider or thinner pathways between areas based on flow of people & goods.A good starting place to look for amazing looking dungeons is to look at people who play Dwarf Fortress, and how they build & organize their forts, which are essentially dungeons.Here are a few good links:http://discourse.stonehearth.net/t/slave-to-armok-god-of-blo...https://leelubutterfly.wordpress.com/2013/01/01/dwarf-fortre...etc. just google image search for "dwarf fortress" and you'll see a lot.Good algorithmic dungeon design should take into account some of these factors, like good city design would.
 > Dungeons are (in theory) built by intelligent people for a reason.Well, in the make believe universes you frequent anyway. Others have different tastes.I mean, in the realm of software there's a whole genre of these things going back to the original Rogue which never pretended to have any purpose at all. And digging even farther back you'll find a dice-driven (and, relative to modern standards, really terrible) random dungeon generator in an appendix at the back of the 1e AD&D DMG. Likewise even earlier TSR products like "Dungeon Geomorphs" were clearly aimed at random-or-at-least-mostly-sensesless generation.That's not to say you can't do better, just that "not random" is probably not exactly the right aesthetic to chase.
 >not exactly the right aesthetic to chaseI'd say not only. A procedural generator that took account of architecture and reason could probably make a more interesting game, not everything needs to point towards that goal, but it'd be neat if some did.I'm bothered more with many first person shooters more which design environments basically just as long kinked up hallways you have to walk through while pretending to be in a place supposably designed with a purpose in mind.
 Think less "town" and more "cave". Spaces created by natural processes also lack any feeling of purposeful design, but still have lots of interesting variation. The feeling of exploring an untamed natural space (which even the creator of the game hasn't seen before!) is part of what makes these games fun, I think.
 Dungeons as portrayed in every video game ever are a fantastic concept. It's not like there are actually anything like real dungeons outside of our imaginations (digging through rock is hard). The closest real analogues would probably be cave systems, like Carlsbad Caverns or Mammoth Cave, which are formed by irregular natural processes.
 the catacombs, perhaps? I've participated in and run more than a few dungeon crawls in catacomb settings
 catacombs (at least those I have visited) have _really_ tiny living spaces, and connections between rooms are basically holes.This is somewhat far from the "the adventurers met a group of monsters in the corridor" or "moria's halls".
 I'm sure that every military has its share of cave complexes built into solid rock. My mandatory service in the Finnish Defense Forces took me to 5 such places, of which at least 3 had multiple levels (I can't say for sure how large any of those were, because they were generally of limits to conscripts; I was only in them because my tasks (mostly installing fiber optics and such) required it).
 Hawaii has dungeons. Defensive positions (and related) built after Pearl Harbor right into the rock. Dungeons exist insofar as dungeons are underground structures built by X that are now left to ruin and hiding strange creatures and hidden treasure. Those places exist on Oahu, among others.
 Mines?
 The Parisian underground system?
 I agree, though the issue, I think, is wider than 'purposeful' design. The dungeon could be a range of things, but this one doesn't look like anything except an 'algorithmic dungeon'. Is it:a) an underground city (your analysis is spot on, doesn't look like that)b) a cave systemc) a mined) a prisone) the lair of some non-intelligent speciesf) a fortress to protect somethingAnother option is that they're supposed to be 'abstract challenge spaces' (as another commenter claims), but roguelikes aren't intentionally abstract: they attempt verisimilitude on lots of levels. Nethack in particular has a very detailed naive physics with all kinds of internal logic.Brogue does its natural caves pretty well, I think. Minecraft seems to, and places its seams of minerals reasonably (neither are perfect, but they're clearly trying).But this kind of dungeon generator? We're nearly 20 years after Crimes Against Mimesis [1] was written, and this feels like a big step backwards.---
 Calling this a step backwards is patently unfair. The author is explaining a simple algorithm, simply enough for even beginners to implement, for building layouts of a given connectedness. They are not making any kind of argument that the results can be used as-is in any particular genre of game.Honestly, you might as well attack an A* pathfinding article on the grounds that game units shouldn't necessarily take the shortest path to their goal. Algorithms like this are tools in a toolbox - obviously tweaking them is what makes any given game unique, but beginners still need to start somewhere.(Also - Nethack? The game where you find potion shops eight levels underground that can only be reached via three rooms full of soldier ants, etc?)
 Good points.Some quibbles:> game units shouldn't necessarily take the shortest path to their goalThey shouldn't? This can in specific cases lead to weird looking behavior, but nobody is suggesting it is an 'abstract movement strategy' that isn't supposed to correspond to anything a person would do. The reason shortest paths are used is that they do correspond to the way people move, to a first approximation.> simply enough for even beginners to implementReally? Using delaunay triangulation, minimum spanning trees and relaxation? With no sample code? This isn't a beginner tutorial.> can be used as-is in any particular genre of game.Really? You don't think this is specifically for roguelikes/roguelites?> NethackNethack definitely has crimes against mimesis too, definitely. In fact it has that 'old adventure' feel. I was using it just to show that the challenge spaces aren't abstract.
 > They shouldn't? This can in specific cases.."Shouldn't necessarily" means shouldn't in some cases, should in others. The point is that something like a pathfinding algorithm is not meant to distinguish between those cases, just as the worldgen algorithm in this article is clearly not attempting to create genre-specific dungeons. It gives you raw information, which you'd need to refine if you wanted to have a feel that's specific to a given game.> This isn't a beginner tutorial.Beginner gamedev. Is this a distinction that you think negates my argument? It sounds like you're listing up everything in my post that you think people could disagree about.> You don't think this is specifically for roguelikes?Whether it's about roguelikes is neither in evidence nor at issue. The parent post took issue with the article for not making maps that felt like a prison/mine/fortress/etc., and I'm saying it clearly didn't attempt to.> Nethack ... the challenge spaces aren't abstract.Every game is abstract in some ways and not in others. But within that universal truth, Nethack is most definitely not a game that even gestures in the direction of realistic world generation, and is a counterexample to the overall point of your post.
 For completeness, i guess most people have seen the ant colony layouts? https://www.youtube.com/watch?v=IGJ2jMZ-gaI https://www.youtube.com/watch?v=CmD5ahkOPAQ
 > There needs to be distinct working, eating, socializing, farming areas. There needs to be wider or thinner pathways between areas based on flow of people & goods.put those constraints as a starting point and use genetic algorithms?
 "Dungeon" is a term in game design to refer to a self contained challenge space, which can be realized in many different ways. It does not necessarily mean "dungeon" as in a real life dungeon or catacomb. It can be an actual human built space, in which case you are right, or it can be a Zelda dungeon, in which there is an overarching theme but not necessarily a sense of verisimilitude, or it can be such a simple and abstracted dungeon such as in Nethack or whatever, in which case those concerns are meaningless.
 This really depends on the game you're making. Some games don't call for super purposeful layouts because the fun comes from things other than your surroundings making a lot of sense. As long as they generally look believable it's mostly fine. And so in those cases as a designer you just really need some places to place enemies in and going for a random enough algorithm is a good idea.
 Dungeons are (in theory) built by intelligent people for a reason.That reason is typically to store something behind a lot of very dangerous traps, trick architecture, and maybe enemies.Unless you're concerned with maintenance, you don't worry about farms and all that other nonsense--that's gold you should've been spending on golems, pit traps, and other self-maintaining defenses!
 I am concerned about your apparent disregard for smashable barrels. It is critical to ensure that payroll and minor health potions are located near at hand to the live defenders of the dungeon, to keep them from loitering around near the nice parts when they should be down patrolling the adventurer-murdering parts.I find the current theory circulating that suggests such placement of critical resources only serves to reinforce and resupply invaders is almost entirely without merit. Why wouldn't a guard take additional effort to defend his barrel? Are they all so incompetent that they would expire before breaking into the emergency medical supplies?
 Here and there. Suppose your dungeon is full of ant people or orcs, creatures that can swing picks but are essentially dumber than the rocks they are hitting. They are rule followers and have not care for design, much like an algo. You can imagine an adventurer having to infiltrate such a place to steal a mcguffin, be it an uber-bee hive, an intestinal system of the dragon that ate you, or the random water paths that carved out a cave. The creator has to give the player a good reason why the system is random.
 Funny you should mention DF. You should look at the procedurally generated dungeons it makes!
 Not every dungeon is built for logistics. Think of temples, tombs, or traps for invaders.
 those are still purpose built however
 [flagged]
 HN staff has made a concerted effort to eliminate gratuitous negativity [0]. It's simple in the case of your post -- eliminate the first and last paragraphs, keeping only the substantive argument ("These dungeons are indeed built by people for a reason... video games... not making a city builder or world sim".)[0] the following comes from https://news.ycombinator.com/newsguidelines.htmlBe civil. Don't say things you wouldn't say in a face-to-face conversation. Avoid gratuitous negativity.When disagreeing, please reply to the argument instead of calling names. E.g. "That is idiotic; 1 + 1 is 2, not 3" can be shortened to "1 + 1 is 2, not 3."
 Dungeons in games have to do two things: serve as spaces of play, and provide verisimilitude, suspension of disbelief. Most often, the first takes high priority, and the second shows up only as set dressing: cells in a prison, waterways in a sewer, altars in a temple, etc.If you look at classic tabletop dungeons, though--the games that gave us the modern meaning of "dungeon" as "enclosed space full of loot and danger" as opposed to the dictionary "underground prison"--you're more likely to see a balance between the two. Everything still serves the needs of play, but within that framework you'll find bunkrooms, kitchens, storage rooms, training areas, etc, etc, sometimes even with discussion of schedules and which characters are likely to be where when, which the players can attempt to learn and take advantage of. It's more work, but it does make the gameworld feel more immersive, more real.Either approach is perfectly valid. In a fast-paced hack-and-slash game, you're not likely to stand still long enough to notice the set dressing; you just need a space in which to kill monsters, and anything more is a waste. In a more thoughtful/exploratory RPG, the game can really benefit from a thoughtful layout.Now isn't it nice when we can disagree without getting all huffy and belligerent?
 I agree with both him and you. But I think part of his point is that often times HN comments tend to focus on kind of irrelevant stuff. I'm the author of this post and the top comment here bothered me a bit because it has nothing to do with the content of the article itself, it's just the top commenter giving his opinions on what types of dungeons he likes better. I didn't even post the article to HN myself because my past experience with comments here (https://news.ycombinator.com/item?id=7540555) were similar in that discussion tends to not be that meaningfully related to what was written.
 Thanks for making the post. Sharing knowledge is great and I appreciate it.I've written a handful of educational posts as well. I swear the majority of comments only exist to make the commenter try to show off how much smarter than the OP they are. Reddit is the absolute worst. But HN isn't far behind.I'm sorry the top comment doesn't actually provide any value to any one. Please don't let dingleberries like him prevent you from writing more in the future. Thanks for sharing.
 The trouble with your posts in this thread is that they make the problem worse by poisoning the well further.We all know that HN has a problem with negative and uncharitable comments. We each need to see it in our own case in order for this to get better.
 He's got a point. Almost none of these algorithms produce a bathroom that's any usable distance from the front door. Imagine you're the resident ogre just back from pillaging and you've got nowhere to go. And the absurdity of a minimally connected dungeon shows itself the first time you have to run to answer the phone.
 I would rather play a game involving a dungeon that was created out of realism than something like "this room is this size because the slime monster that lives here is what the PCs need to encounter now". Also I find your comment needlessly aggressive, in addition to it smelling like you are the only one that knows what is best for gamers and game designers.

Search: