Roguelike: Synthesis
Combine all four map generation algorithms behind a strategy enum — switch generators and regenerate maps with new seeds at the press of a key.
No login required.
Algorithm Switcher
Combine all four generators behind a single enum and add keyboard-driven regeneration. Switch algorithms with arrow keys and generate new maps with spacebar.
The Strategy pattern lets you swap algorithms at runtime -- a fundamental design pattern used everywhere from game AI to rendering backends.
Loading game...
Click the game window to interact with it
What You'll Build
You will combine all four map generation algorithms behind one enum and a match statement — the strategy pattern. Press right arrow to cycle between Drunkard's Walk, Cellular Automata, BSP, and Noise Terrain. Press spacebar to regenerate with a new seed. All four generators write to the same grid format, so swapping them is a one-line change. Seeing the algorithms side by side makes the tradeoffs concrete: drunkard's walk carves winding caves, cellular automata produces smooth chambers, BSP creates structured rooms, and noise terrain generates natural islands.
How it works
- 1
Define an enum for each generator type
Create an enum with one value per algorithm: DRUNKARD, CELLULAR, BSP, NOISE. Store the currently active generator in a variable typed to this enum. The enum gives you readable names instead of magic numbers.
- 2
Route to the right generator with match
A match statement checks the active enum value and calls the corresponding generation function. Each function takes the same grid and RNG, so the rest of the code doesn't need to know which algorithm is running. This is the strategy pattern — swap behavior by changing one value.
- 3
Add keyboard-driven regeneration
Handle input events with is_action_pressed(). Spacebar increments the seed and regenerates with the same algorithm — same strategy, new map. Right arrow cycles to the next enum value and regenerates — new strategy, new map. This gives instant visual feedback for comparing algorithms.
Learning Goals
- ✓Enum definition with named constants for each generator type
- ✓Match statements that dispatch to the correct generation function
- ✓Input handling with is_action_pressed() for seed regeneration and algorithm cycling
- ✓Shared interface pattern — all generators accept the same grid and RNG, making them interchangeable
GDScript Concepts in This Part
Tips
- ✨Define a clear generate(grid, rng) interface that all four algorithms follow — this is the strategy pattern in practice.
- ✨Print the current seed and algorithm name to the console so you can reproduce any interesting map.
- ✨Adding a fifth algorithm later is just one new enum value and one new match arm. The architecture makes extension trivial.