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 want to generate a town layout in a square grid (rendered isometrically, but that doesn't matter) using the following elements:

  • 2x2 Houses
  • Roads, 1 unit wide
  • Canals, 1 unit wide

Sample layout:

Sample layout

  • I always have a specific number of houses, and as many roads and canals as necessary to connect them all.
  • The houses need to have two pieces of road in front of their front door (which is always pointing to the right)
  • It would be nice to have fields of grass (emptiness) inbetween.

Is there a ready-made algorithm for this? If not, what direction should I be thinking of to implement this?

share|improve this question

1 Answer 1

up vote 8 down vote accepted

There are many ways to go depending on exactly how you want it. Here is a rough outline of one way which I think will fit your description:

First generate the canals. Then start placing houses randomly, for each house you place, place the road in front of it and draw a road from that piece to the existing road network, if either is not possible or placing the road in front results in an ugly 2x2 block of road reposition the house. Detect some road points that are close to each other but far apart following the existing roads and try to make some shortcuts for those.

This kind of stuff most of all takes experimentation and experience. Often you'll get good results from making some detail in a random fashion, determine if it meets some criteria and undo and retry if it doesn't.

For this exact task you will certainly also need a good grasp of basic pathfinding, unless you are already an expert, go read on the topic. And remember, pathfinding doesn't have to be just about the shortest path, for the last part of my description you might want to give some weight to reusing paths that are already there.

This is not at all an easy task, if you get stuck come back and show us your code and some example output and explain in detail how you would like it to be different.

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.