## Monday, April 23, 2012

### Some PCG Algorithms for Dungeon Generation

Recursive Backtracker Maze Algorithm:
- Go in random unvisited direction and backtrack when each direction is visited until everything is visited

Jar Demo:
http://dl.dropbox.com/u/30075723/joe/RecursiveBacktracker.jar

Jamis Buck Maze Algorithm:
- Similar to Recursive Backtracker
- Addition of some parameters that control bias of turning

Jar Demo:
http://dl.dropbox.com/u/30075723/joe/JamisBuck.jar

Recursive Backtracker (left) versus Jamis Buck (right)

Cellular Automata:
- Change the state of a grid cell (whether it can be walked on or not) based on neighboring states
- If (parameter_above = 5) or more of neighbors are "walkable" then this cell is walkable.
- If (parameter_under = 2) or less of neighbors are NOT "walkable" this this cell is non-walkable.
- Run the above to "erode" the dungeon
- No guarantee of connectedness without further work

Examples of Cellular Automata:
http://www.grabilla.com/02418-3a42a206-b903-439f-986a-55f0b6cb5794.png
http://www.grabilla.com/02418-bfaf95c7-f212-4d47-b5ca-e78217c8a7d8.png

Jar Demo:
http://dl.dropbox.com/u/30075723/joe/CellularAutomata.jar

BSP Tree (Binary Space Partion):
- Split the component in half either vertically or horizontally at some position
- Recurse into each half and repeat until the components are "small enough"
- Add rooms to each resulting component after tree is generated
- Connect rooms (by connecting each component to its sibling)
- Connectedness *is* guaranteed as a property of the BSP Tree

Examples of BSP Tree Dungeons:
http://www.grabilla.com/02418-eab66c9e-2e3b-402a-89df-fcb6ff589c6c.png