Hacker News new | ask | show | jobs
by doomlaser 4194 days ago
Another cheap and very effective technique for procedural level and maze generation is to create a "walker" or series of walkers that start at some point, walk in a direction and then turn at random intervals, leaving a path of corridors and occasionally rooms in their wake. This is how Vlambeer's Nuclear Throne generates its levels, and there's a good article from Jan Willem Nijman, it's developer, here: http://www.vlambeer.com/2013/04/02/random-level-generation-i...

If you'd like a more academic look into procedural 2d game generation, there's a nice research paper here, that describes a method and talks about Spelunky a lot (the king of procedural 2d level generation, in my book): http://games.soe.ucsc.edu/sites/default/files/cig10_043CP2_1...

Additionally, Derek Yu open sourced the code to the original Spelunky, and Darius Kazemi created a great breakdown of its level generation techniques here, also with interactive examples: http://tinysubversions.com/spelunkyGen/index.html

The action roguelike genre, particularly the roguelike FPS, is a vital new area being explored by indie game developers. It reminds me of the way 2D platformers were mined, explored, and iterated upon starting around 7 or 8 years ago.

Right now, it doesn't take much to stand out from the herd, as many of the most popular games in the genre don't do much beyond generating a bunch of square rooms and connecting them with doors and short, straight corridors. In my opinion, developers in the genre should take more cues from Doom, and less from original Zelda dungeons moving forward.

And, from a more holistic perspective, nobody really cares about mazes, room placement on a grid, and connective corridors when playing a game, beyond a brute mechanical level. A more useful framework for thinking of generating levels might be to go one level of abstraction higher. Think about a level as a story for your player, and generate setpieces or 'acts' that you want the player to experience as they play. Keep in mind the basics of a good story: an escalation in tension and difficulty, spaced with breathers for rhythm and flow. Place those sets on a path in a map, then figure out a way to connect them together at the lower level with rooms, objects, enemies, and corridors.

4 comments

These links are awesome. I've considered an "incremental digger" model like Nuclear Throne's before. I like that they're "realistic" in that they sort of simulate how creatures would have created the dungeon. I haven't played with them enough to see if I can get fun results out of them, but now I find myself wanting to try.

> Keep in mind the basics of a good story: an escalation in tension and difficulty, spaced with breathers for rhythm and flow.

It's out of scope for this article, but my little game tries to do some of that. Once the dungeon is generated, it chooses a random starting place for the player. Then it calculates the distance to that tile for every other tile.

When monsters, treasure, and quest goals are placed, those distances are taken into account. Harder monsters and better stuff are placed (roughly) farther from the player, so it feels like there's a general progression in difficulty and reward as you go farther through the dungeon.

There's definitely a lot more I could there.

Now that I think about it, one simple refinement would be:

1. Place all of the monsters first.

2. Recalculate distances and treat tiles near monsters as being "high distance" based on the monster's strength so that paths that go through monsters become "longer".

3. Now place treasure according to that.

That would give you dungeons where monsters "guard" better treasure, and stronger monsters protect better loot.

You could enhance that second point by adding some noise to the function so the difficulty isn't a smooth ramp — you get some tough monsters earlier and then maybe the next group isn't as difficult.
Right. I fuzz that on the other end in my game: the distances are calculated accurately, but the monsters are distributed semi-randomly by distance.

The basic process is:

1. Pick a random difficulty for the monster. 2. Pick n random locations for the monster and place it at the farthest one.

n is based on the monster's difficulty so stronger monsters get more chances to end up farther away. This means you can still run into really hard stuff early, it's just less common.

As another resource, here's a draft chapter on dungeon generation, from a textbook on procedural content generation in games: http://pcgbook.com/wp-content/uploads/chapter03.pdf

(Draft in part because some of the figures still need work. I'm a coauthor of the book, but not of this particular chapter.)

Can I take a moment to be critical here? I hate sounding negative, but I'll try to be constructive.

I was really excited when I first stumbled onto this book. As you can imagine, it's perfectly in line with my interests. But, when I tried to read it, the prose just killed me. I think there's good ideas in there, but I can't bear to wade through the heavy-handed academic style get there.

I understand writing for a certain venue requires certain stylistic choices, but I really hope you guys can tone it down a bit. Here's a sentence plucked randomly from the linked chapter:

> "Generative grammars were originally devised as a method to formally describe sets of linguistic phrases."

Let me just go through that:

"originally devised" -> "Devise" implies originality.

"as a method" -> This adds nothing to the sentence.

"formally" -> I suppose this matters in some cases but given that the chapter isn't a precise introduction to generative grammars, whether or not it's a formal system doesn't seem very critical to me.

"sets of" -> This adds nothing.

"linquistic" -> What other kinds of phrases are there?

I would edit this sentence down to:

> Generative grammars were invented to describe written text.

I understand academic writing isn't designed to be read for pleasure, but we're all human. If you make the prose more approachable, you'll reach a much wider audience. You have some fantastic material in here, great algorithms, diagrams, and structure. I just feel that the writing style gets in the way of it.

If I could suggest anything, it's that the authors go through the prose and for every phrase ask themselves: "Does this add information? Is there a way to convey the same concept in plainer language?"

This is not "academic writing", it is writing trying to sound academic. At my University you would get higher regard for your version and consequently better marks.

If it is a subject you are interested in, then George Orwell's essay on writing style [1] is worth a read.

[1] https://www.mtholyoke.edu/acad/intrel/orwell46.htm

Indeed it is!

I also highly recommend William Zinsser's On Writing Well. It's a perfect gem of a book and improved my writing more than anything else ever has.

I'm on chapter 6, all good so far. Thanks for the recommendation.

The full text is available online

https://archive.org/details/OnWritingWell

To nitpick your nitpick (and not to imply your ultimate conclusion is wrong):

    "originally devised" -> "Devise" implies originality.
The word original in the original text is used in the sense of "from or in the beginning; at first", while you seem to be taking it in the sense of "in a novel and inventive way".

The phrase "originally devised" implies the usage of the devised thing has since changed or expanded beyond the purpose of its invention. This is important, because it is in a passage talking about one of those new usages - dungeon generation.

Yes, your sentence has the same meaning, and in a weak sense has the same implication, but "originally devised/invented" has a history that boosts that implication to make the purpose clearer.

"linquistic" -> What other kinds of phrases are there?

Musical phrases.http://en.wikipedia.org/wiki/Phrase_%28music%29

Means almost the same thing as linguistic phrases except it is about groups of notes rather than groups of words.

A reasonable point. I've been doing a bit of editing for style recently, and will make another pass before sending off the manuscript. At the moment the style is very uneven from chapter to chapter, partly because the authors come from different backgrounds. If you include chapter authors, we live in 6 countries and have 9 native languages between us, and different views on how a textbook should read. To generalize really broadly, the text from Americans and Scandinavians seems to use shorter sentences and a more conversational tone than that from others. (Of course, country/language isn't the only reason people vary on style and level of formality.)

But yes, I'm aiming to bring it in a more conversational direction. It still needs editing too, but Ch. 8 is closer to the style I'm personally aiming for.

I just read Steven Pinker's "The Sense of Style" and found it to be an excellent resource on this topic.

http://www.amazon.com/The-Sense-Style-Thinking-Person%C2%92s...

From that text

“A coherent text is one in which the reader always knows which coherence relation holds between one sentence and the next.”

Sage advice indeed.

http://www.telegraph.co.uk/culture/books/bookreviews/1108972...

Adom is a roguelike that does your "holistic perspective" very well - it mixes an overall story arc and set piece locations with a lot of randomised elements. It's going through a bit of a renaissance after raising 90k on IndieGoGo.
Have you seen Brogue? It's level design is pretty incredible. I do love Spelunky but I think Brogue, from a design and technical perspective, is better.

One area I've been experimenting in is constraint-based solvers in my generators. It requires keeping track of rooms or regions but allows the algorithm to express ideas like: this room has a health potion but the boss cannot be within 2 rooms of it. You can of course get more creative with your constraints. I'd like to build up the ability to have sophisticated (for some value of sophistication) puzzles built into the dungeons I generate.

Brogue is indeed really impressive with level generation (and also gameplay!). I still wonder how holes and deep water are positionned.