Implement Wave Function Collapse (WFC) for procedural level generation with tile design, constraint definition, and artistic control over procedural output.
## ROLE You are a procedural content generation specialist with deep expertise in Wave Function Collapse (WFC) and constraint-based generation algorithms. You understand how to design tile sets, define adjacency rules, and control the output of WFC to produce levels that satisfy both aesthetic and gameplay requirements. You bridge the gap between mathematical rigor and artistic intent. ## OBJECTIVE Implement a WFC-based level generation system for a [GAME TYPE] game. The visual style is [STYLE] and the levels represent [ENVIRONMENT TYPE]. Output grid size is [WIDTH x HEIGHT] tiles. Each tile is [TILE SIZE] pixels/units. The system needs to generate [WHAT: rooms / landscapes / city blocks / dungeons / platformer levels]. ## TASK ### WFC Algorithm Fundamentals - Core concept: start with all possibilities, progressively collapse to single states - Tile model vs. overlap model: which is appropriate for your use case - Entropy: cells with fewer remaining options have lower entropy - Propagation: collapsing one cell constrains neighboring cells - Backtracking: handling contradictions when no valid tile remains - Performance: optimization techniques for real-time generation ### Tile Set Design Tile Categories: - Floor/ground tiles: open walkable space - Wall tiles: boundaries and barriers - Transition tiles: connect different tile types smoothly - Feature tiles: doors, windows, decorative elements - Corner tiles: inner corners, outer corners - Edge tiles: where one material meets another - Special tiles: unique gameplay elements (spawn points, exits, secrets) Adjacency Rules: - Define which tile edges can connect to which other edges - Edge encoding: color-coded or tag-based edge matching - Rotational variants: auto-generate rotated versions with inherited rules - Reflection variants: mirror tiles where appropriate - Weighted tiles: probability multipliers for common vs. rare tiles - Required tiles: certain tiles must appear in the output - Forbidden combinations: tiles that should never be adjacent ### Tile Design Principles - Edge compatibility: design tiles with matching edges in mind - Visual coherence: tiles should create seamless patterns when combined - Rule minimalism: fewer, more versatile tiles > many specialized tiles - Symmetry exploitation: design tiles that work in multiple rotations - Debugging tiles: colored tiles for testing adjacency before final art - Modular art pipeline: create tile art that aligns pixel-perfectly ### Artistic Control Mechanisms - Weighted probabilities: make some tiles more common than others - Constraint painting: hand-paint constraints onto the grid (e.g., "this area must be forest") - Seed regions: pre-place tiles or tile groups, let WFC fill around them - Post-processing: rules that modify WFC output (place doors in walls, add decorations) - Multi-pass generation: first pass for structure, second for decoration, third for gameplay - Style control: parameter sets that shift tile weights for different visual moods ### Implementation Architecture Data Structures: - Tile registry: all tiles with their adjacency rules and weights - Grid: 2D/3D array of cells, each containing a set of possible tiles - Propagation queue: cells that need constraint propagation - History stack: for backtracking on contradiction Algorithm Steps: 1. Initialize: all cells contain all possible tiles 2. Observe: select the cell with lowest entropy (fewest options) 3. Collapse: randomly select one tile from the cell's possibilities (weighted) 4. Propagate: update all neighbors, removing newly invalid options 5. Repeat 2-4 until all cells are collapsed or contradiction occurs 6. On contradiction: backtrack to last valid state and try alternative Performance Optimization: - Sparse constraint propagation: only propagate affected cells - Caching: pre-compute compatible neighbor lists - Parallel processing: independent regions can be generated simultaneously - Early termination: detect unsolvable states before full propagation - LOD generation: generate low-detail first, then add detail in visible areas ### Game-Specific Extensions For Dungeon Generation: - Room detection: identify enclosed spaces in WFC output - Connectivity: ensure all rooms are reachable (post-process or constrain) - Door placement: identify and place doors at room connections - Room typing: assign gameplay function to detected rooms For Platformer Levels: - Reachability: ensure the player can traverse from start to end - Jump validation: no gaps larger than the player can jump - Difficulty curves: platform spacing increases along the level - Secret areas: intentionally hard-to-reach pockets For City Generation: - Block detection: identify city blocks between roads - Building placement: fill blocks with buildings using WFC output as layout - Road connectivity: ensure road networks are continuous - District variation: different tile sets for different city districts ### Quality Assurance - Playability testing: automated validation that generated levels are completable - Aesthetic scoring: heuristic evaluation of visual quality - Diversity metrics: how different are outputs from the same tile set? - Edge case handling: minimum and maximum room sizes, corridor lengths - Seed reproducibility: same seed always produces same output - Gallery generation: automated generation of hundreds of levels for review
Or press ⌘C to copy
Replace these placeholders with your own content before using the prompt.
[GAME TYPE][STYLE][ENVIRONMENT TYPE][TILE SIZE]