# Generowanie z lokalnych wzorów (Wave Function Collapse)

EN: **Wave Function Collapse and constraint-based generation** · id `wfc` · aliases: Wave Function Collapse, WFC, model synthesis, constraint-based PCG, generowanie z ograniczeń, kafelkowe generowanie map

Path: [AI Atlas](https://aiatlasgraph.com/llms.txt) › [AI w grach](https://aiatlasgraph.com/t/gameai.md) › [Proceduralne generowanie treści gier](https://aiatlasgraph.com/t/pcg.md) › Generowanie z lokalnych wzorów (Wave Function Collapse)

## Description

- PL: Generowanie map i tekstur przez rozwiązywanie ograniczeń sąsiedztwa wyuczonych z przykładu lub zadanych listą kafelków, z wyborem komórek o najmniejszej entropii.
- EN: Generating maps and textures by solving neighbourhood constraints learned from an example or given as a tile list, collapsing the lowest-entropy cells first.

## In one sentence

- PL: Algorytm, który z małego przykładu mapy albo zestawu kafelków układa dużą, nową mapę zgodną z tym, co do czego pasuje.
- EN: An algorithm that takes a small sample map or tile set and assembles a large new map where every piece fits its neighbours.

## Problem it solves

- PL: Ręczne układanie tysięcy kafelków trwa wieki, a zwykłe losowanie daje drogi urwane w pół i ściany w środku rzek.
- EN: Placing thousands of tiles by hand takes forever, and plain randomness gives roads that end abruptly and walls in rivers.

## What it does

- PL: Jak składanie puzzli od najpewniejszego miejsca: kładziesz element, który pasuje najmniej sposobów, i od razu wykluczasz te, które przestały pasować obok.
- EN: Like doing a jigsaw from the surest spot: place the piece with the fewest options, then rule out neighbours that no longer fit.

## Everyday example

- PL: Gra budowlana, w której dokładasz dom, a mury, mosty i schody wokół same dopasowują się do terenu.
- EN: A town-building game where you add a house and the walls, bridges and stairs around it fit themselves to the terrain.

## This concerns you if you…

- PL: tworzysz mapy z kafelków albo pixel art
- PL: chcesz generować świat zgodny z ręcznym stylem
- EN: make tile maps or pixel art
- EN: want to generate a world that keeps a hand-made style

## Keywords

Wave Function Collapse · model synthesis · constraint propagation · tilemaps · overlapping model · simple tiled model · answer set programming

## How it works

- PL: Każda komórka startuje z listą wszystkich dozwolonych wzorów. Algorytm wybiera komórkę o najmniejszej entropii, losuje jej wzór z wagami częstości, a potem propaguje ograniczenia, usuwając niepasujące opcje u sąsiadów. Powtarza to, aż wszystko jest ustalone albo pojawi się sprzeczność wymagająca restartu lub cofania.
- EN: Each cell starts with a list of all allowed patterns. The algorithm picks the lowest-entropy cell, samples a pattern weighted by frequency, then propagates constraints by removing incompatible options from neighbours. It repeats until everything is set or a contradiction requires a restart or backtracking.

## Limits

- PL: Algorytm pilnuje tylko lokalnego sąsiedztwa, więc globalna struktura, np. jedna droga przez całą mapę, wymaga dodatkowych ograniczeń. Może utknąć w sprzeczności, a ogólny problem jest NP-trudny. Najlepiej działa na pixel arcie i mapach kafelkowych.
- EN: It only enforces local neighbourhoods, so global structure, like one road across the map, needs extra constraints. It can hit contradictions, and the general problem is NP-hard. It works best on pixel art and tile maps.

## Key terms

- PL: **entropia komórki**: Miara, ile różnych wzorów może jeszcze trafić w to miejsce.
- PL: **propagacja ograniczeń**: Usuwanie opcji u sąsiadów po każdym ustaleniu komórki.
- PL: **sprzeczność**: Komórka bez żadnej dozwolonej opcji; generowanie trzeba cofnąć.
- EN: **cell entropy**: How many patterns could still go in that spot.
- EN: **constraint propagation**: Removing neighbours' options after each cell is fixed.
- EN: **contradiction**: A cell with no allowed option; generation must back up.

## Know first

- [Problemy z ograniczeniami (CSP) (Constraint satisfaction problems (CSP))](https://aiatlasgraph.com/t/csp.md)

## Related topics

Untyped, symmetric "see also" links.

- [Generowanie z gramatyk i L-systemów (Grammars and L-systems for content generation)](https://aiatlasgraph.com/t/grammarpcg.md)
- [Problemy z ograniczeniami (CSP) (Constraint satisfaction problems (CSP))](https://aiatlasgraph.com/t/csp.md)

## Sources

- [WaveFunctionCollapse (repository and README)](<https://github.com/mxgmn/WaveFunctionCollapse>) `mxgmn-wavefunctioncollapse` · by mxgmn (Maxim Gumin)

---

AI Atlas revision 122 (2026-10-30) · HTML: https://aiatlasgraph.com/t/wfc · index: https://aiatlasgraph.com/llms.txt · everything: https://aiatlasgraph.com/llms-full.txt · updated 2026-10-30
