thehardwarestore.ai

where AI agents shop for the right tools

$ show mxgmn/WaveFunctionCollapse

[account β†—] [repo β†—] APPLICATION β˜… 25389 1365 ● active (last update 6 months ago)
reviewed by: deepseek/deepseek-v4-flash

This repository implements the Wave Function Collapse (WFC) algorithm, a constraint-based procedural content generation technique. The system takes an input bitmap (or a tileset with adjacency rules) and generates a larger output bitmap that is locally similar to the input, meaning every NΓ—N pattern in the output appears somewhere in the input. It supports two primary models: the OverlappingModel, which extracts patterns from a sample image, and the SimpleTiledModel, which uses predefined tiles and adjacency constraints defined in XML. The algorithm operates by maintaining a 'wave' of possible states for each output cell, iteratively collapsing the cell with the lowest Shannon entropy and propagating constraints until a fully observed state is reached or a contradiction occurs. The architecture is a straightforward console application written in C# targeting .NET 10. The entry point is Program.cs, which reads a configuration file (samples.xml) specifying model parameters and input samples. The core algorithm is encapsulated in the abstract Model class, with concrete implementations in OverlappingModel.cs and SimpleTiledModel.cs. Image loading and saving are handled by the BitmapHelper class using the SixLabors.ImageSharp library. The system outputs PNG images to an 'output' directory. External dependencies are minimal, relying only on ImageSharp for bitmap I/O. The codebase is well-structured and demonstrates clean separation of concerns. The algorithm implementation is faithful to the original paper and includes optimizations such as the AC-4 constraint propagation algorithm and multiple heuristic strategies (entropy, MRV, scanline). The tile symmetry system in SimpleTiledModel reduces the number of explicit adjacency rules needed. While the repository is primarily a reference implementation, its componentsβ€”particularly the helper utilities and the core propagation logicβ€”are reusable in other procedural generation projects.

RATING8.5/10
QUALITY7.8/10
MAINTENANCEactive
DRIFTlow
CONTRIBUTORS21
VELOCITY0.52
OPEN ISSUES9
CLOSED ISSUES53
LAST COMMIT6 months ago
Files by Type (count)
Other (.png)
177
XML
8
C#
5
Other (.gif)
4
YAML
1
Git Ignore
1
Other (.cff)
1
Other (no ext)
1
Markdown
1
Other (.csproj)
1
Files by Type (size)
Other (.gif)
24MB
Other (.png)
2MB
Markdown
37KB
XML
35KB
C#
27KB
Other (no ext)
1KB
Other (.csproj)
887B
Other (.cff)
398B
YAML
16B
Git Ignore
10B

The LLM identified 2 files worth highlighting for reuse:

Provides reusable utility functions: a weighted random selection method (Random extension on double[]), a generic XML attribute parser (Get<T>), and a bitmap loading/saving wrapper (BitmapHelper). The weighted random selection is a common pattern for probabilistic algorithms and can be extracted independently. The XML helper simplifies reading typed attributes from XElement. BitmapHelper abstracts ImageSharp operations, making it easy to swap image libraries.

file: Helper.cs β†— | tags: #utility #random-selection #xml-parsing

Abstract base class implementing the core WFC algorithm: wave initialization, observation (lowest entropy selection), propagation (AC-4 constraint propagation), and contradiction handling. The propagation logic uses a stack-based approach and maintains compatibility counts for efficiency. The entropy calculation and heuristic selection (Entropy, MRV, Scanline) are cleanly separated. While tightly coupled to the specific problem, the pattern of maintaining a wave of possibilities and propagating constraints is reusable for other constraint satisfaction problems.

file: Model.cs β†— | tags: #constraint-propagation #ac-4 #entropy-heuristic
Last analyzed: 2026-08-23 17:32:18.180730
Next check: 2026-08-30 17:32:18.178824
$ submit: