Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am planning on making a (simple) procedural city generator using Java. I need ideas on whan algorithm to use for the layout, and the actual buildings. The city will mostly have skyscrapers, not really much complex stuff.

For the layout I already have a simple algorithm implemented:

  1. Create a Map with java.awt.Point keys and Integer values. Fill it with all the points in the city's bounds with the value as -1 (unnassigned)
  2. Shuffle the map, and assign the 1st 10 of the keys IDs (from 1-10)
  3. Loop until all points have IDs:
  4. Loop though all points:
  5. Assign points next to an assigned point IDs of the point next to them, if 2 or more points border the point, then randomly choose which ID the point will get.
  6. Stop looping #3-5 when all points have ids
  7. You will end up with 10 random regions. Make roads bordering these regions.
  8. Fill the inside of each region with a randomly spaced and randomly rotated grid

PROBLEM: This is not the fastest way to do it.

What algorithm should I use for the layout. And what should I use to make each building's design? I don't even know how I'm going to do that yet (fractals maybe). I just need some ideas, not actual code.

share|improve this question
    
I'm not sure the algorithm will work as you list it out. In step 3, you assign all points IDs. In step 5, you assign points next to an assigned point (which is all of the points) the ID of the point next to them. So you're going through and changing all of the IDs points you have assigned. Because of this, you'll have a jumble of tiny little islands of each ID, not 10 individual regions. –  fnord Nov 15 '12 at 23:21
    
relevant: Pixel City. youtube.com/watch?v=-d2-PtK4F6Y –  Trevor Powell Nov 15 '12 at 23:24
    
it doesn't explain you how it is done, but might give you some ideas : youtube.com/watch?v=FR9xI0GgrBY (city) and youtube.com/watch?v=tUwHRc2zpbo (office generation) –  tigrou Nov 16 '12 at 0:04
    
Saskia Groenewegen's thesis might give you some ideas: graphics.tudelft.nl/Game_Technology/Groenewegen –  amitp Nov 16 '12 at 0:44
1  
@Trevor - Shamus has had a blog about this for a while. A very good read in my opinion. shamusyoung.com/twentysidedtale/?p=2940 –  Feltope Nov 16 '12 at 4:43
show 3 more comments

closed as primarily opinion-based by Byte56 Feb 4 at 15:24

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

The procedure you've described seems to be about generating a number of regions on your map. For this problem, I'd suggest using a voronoi diagram instead. A nice tutorial for generating one can be found here. I think this would be faster than your algorithm.

Looking further ahead to road and building generation, there are a lot of different algorithms because of the different requirements. Is this a modern American city with sky-scrapers and suburbs or a historic Roman city with temples and 1-story buildings? This type of difference will affect what you want from your city generator.

If you're interested in reading some academic stuff, I'd recommend a couple of papers on Pascal Müller's site.

share|improve this answer
    
it's a modern american city. Sorry for the confusion –  Zove Games Nov 16 '12 at 20:38
1  
Thanks for the answer though. I'll look into the voronoi diagrams. –  Zove Games Nov 16 '12 at 20:39
add comment

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