Skip to content

Instantly share code, notes, and snippets.

@ebonneville
Created October 24, 2012 21:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ebonneville/3949171 to your computer and use it in GitHub Desktop.
Save ebonneville/3949171 to your computer and use it in GitHub Desktop.
Basic cellular automata algorithm
1. Scatter wall blocks across the level at a 30-40% saturation level (I've found that 39% is ideal).
2. Iterate through all the tiles on the map four times:
- For each tile in each iteration, set the tile to be floor.
- Then, calculate the number of wall tiles within both one square of the original tile (these are neighbors) and two squares (these tiles are nearby). Store these numbers.
- If the number of neighbors for the tile is greater than or equal to 5, or there are less than two wall tiles nearby, set this tile to be a wall.
- If it is not a wall already, leave this tile as a floor tile.
3. Iterate through all the tiles on the map three more times:
- For each tile in each iteration, set the tile to be floor.
- Calculate the number of wall tiles within both one square of the original tile.
- If this tile has five or more neighboring walls, make it a wall. Otherwise, leave it as a floor tile.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment