Hacker News new | past | comments | ask | show | jobs | submit login

This is one of the classic procedural algorithms. I wrote my first version fifteen years ago; it's quite nostalgic :)

The other classic algorithm that I've gotten the most mileage out of is: http://www.roguebasin.com/index.php?title=Basic_BSP_Dungeon_... . Using rooms the size of entire subdivisions (instead of the smaller ones on that page) makes a nice contrast with the cellular cave algorithm.

The only algorithm I've come up with that's nearly as nice as these two is competitive flood fill. First you randomly pick center points for rooms, create a priority queue of [distance to room center -> room + tile], and add the room centers to the queue. Then you repeatedly pop tiles, add them to the corresponding room, and add their neighbors to the queue, until all tiles are in rooms. This is basically a discrete version of a voronoi diagram, but the trick is that implementing it this way allows you to safely mix different ways to measure distances, and you get wild shapes when some rooms use manhattan distance and others use euclidiean distance. (Some day I'll do a proper writeup of this, but not today.)




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: