Roguelike: Cellular Automata
Smooth random noise into natural cave chambers using the cellular automata 4-5 rule — fill the grid, count neighbors, snapshot state, and iterate.
No login required.
Random Noise
Cellular automata starts with random noise -- each cell has a chance of being wall or floor. You'll fill the grid randomly, then learn to count neighboring walls.
Random initialization creates the raw material that smoothing will sculpt into natural-looking caves.
Loading game...
Click the game window to interact with it
What You'll Build
You will implement cellular automata to generate smooth cave chambers. Start by randomly filling the grid (each cell has a ~45% chance of being a wall), then repeatedly apply the 4-5 rule: a cell becomes a wall if 5+ neighbors are walls, or becomes floor otherwise. After a few iterations, random noise smooths into natural-looking chambers.
Learning Goals
- ✓Random grid initialization with probability thresholds
- ✓Neighbor counting in a 3×3 neighborhood (Moore neighborhood)
- ✓Double-buffering: reading from a snapshot while writing to the live grid
- ✓Iterating the automaton for a fixed number of generations
GDScript Concepts in This Part
Tips
- ✨Always read from a snapshot copy of the grid and write to the original — modifying cells in place while counting neighbors produces incorrect results.
- ✨Four to five iterations is usually enough; more iterations over-smooth the map.