Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm looking to do some pseudo-random map generation using graph grammars (graph rewriting). However, most of what I can find online on this is purely academic and, while helpful, doesn't have any direct practical application.

For the uninitiated, the thousand-foot view of this is that say a dungeon room is generated, then based on a set of rules for that room, one rule is randomly chosen and applied adding more rooms. From there, another specified room may go through the same or a different set of rules for additional growth of the map.

For the practical side of things, I'm thinking of storing the possible rules as arrays containing data about what additional rooms it contains, what order they are in, and which might also end up having a rule applied to it. But then mapping this to 2D space, while it seems easy, may end up with some complications, such as what happens if rooms end up overlapping.

At any rate, I was hoping someone might have some insight into whether this might be done in a better fashion than an array for the rules.

The results from the rules will likely be added to a custom class that will hold the layout as it's built.

Thoughts? :)

share|improve this question
2  
graph-grammars is probably a bit too niche for a GDSE tag, added procedural-generation instead – Pikalek May 23 at 15:43
1  
well, if you span your graph starting from 1 room, you could just move overlapping rooms until the first non-occupied spot. Taking suggestion from this, when the algorithm separates the rooms. You could just span them untile they don't overlap – Leggy7 May 23 at 16:07

Most instances I've seen of graph rewriting for map generation solve the collisions problem (I.E overlapping rooms) by restricting the graph nodes to regular, modular components. For instance, this example, taken from Procedural generation of dungeons uses rooms that are laid out on regular intervals:

enter image description here

share|improve this answer

The other approach I've seen is to use a generate & test (aka trial & error) approach. Basically, a rule is selected & if the result would be valid, it is applied. If the result is invalid (I.E. overlapping rooms) usually it is discarded & a new rule is attempted. Other times, it may be possible to modify the results.

In a sense, both of these happen a bit with Brogue's level generation; I.E. bridges are built "until we can't find nice places to build them" whereas with water "we knock down the boundaries between similar lakes where possible."

The more complex your rules, the more difficult it may be to get results with a no modifying generate & test approach. The trade off is it can generate things of greater complexity than the modular approach discussed on my other answer.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.