Skip to content

Commit

Permalink
new N=4 examples, make rng local, how to run in release mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mxgmn committed Aug 31, 2021
1 parent d850f66 commit 8bbf089
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 12 deletions.
1 change: 1 addition & 0 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ message: "Please cite if you use WFC in your research."
authors:
- family-names: Gumin
given-names: Maxim
email: [email protected]
title: Wave Function Collapse Algorithm
version: 1.0
date-released: 2016-09-30
Expand Down
12 changes: 6 additions & 6 deletions Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ abstract class Model
(int, int)[] stack;
int stacksize, observedSoFar;

protected Random random;
protected int MX, MY, T, N;
protected bool periodic;

Expand Down Expand Up @@ -82,14 +81,14 @@ public bool Run(int seed, int limit)
if (wave == null) Init();

Clear();
random = new Random(seed);
Random random = new Random(seed);

for (int l = 0; l < limit || limit < 0; l++)
{
int node = NextUnobservedNode();
int node = NextUnobservedNode(random);
if (node >= 0)
{
Observe(node);
Observe(node, random);
bool success = Propagate();
if (!success) return false;
}
Expand All @@ -103,7 +102,7 @@ public bool Run(int seed, int limit)
return true;
}

protected int NextUnobservedNode()
protected int NextUnobservedNode(Random random)
{
if (heuristic == Heuristic.Scanline)
{
Expand Down Expand Up @@ -139,7 +138,7 @@ protected int NextUnobservedNode()
return argmin;
}

void Observe(int node)
void Observe(int node, Random random)
{
bool[] w = wave[node];
for (int t = 0; t < T; t++) distribution[t] = w[t] ? weights[t] : 0.0;
Expand Down Expand Up @@ -217,6 +216,7 @@ protected virtual void Clear()
sumsOfWeights[i] = sumOfWeights;
sumsOfWeightLogWeights[i] = sumOfWeightLogWeights;
entropies[i] = startingEntropy;
observed[i] = -1;
}
observedSoFar = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion OverlappingModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public override Bitmap Graphics()
Bitmap result = new Bitmap(MX, MY);
int[] bitmapData = new int[result.Height * result.Width];

if (NextUnobservedNode() < 0)
if (observed[0] >= 0)
{
for (int y = 0; y < MY; y++)
{
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ One of the dimensions can be time. In particular, d-dimensional WFC captures the
## How to build
WFC is a console application that depends only on the standard library. Get [.NET Core](https://www.microsoft.com/net/download) for Windows, Linux or macOS and run
```
dotnet run WaveFunctionCollapse.csproj
dotnet run --configuration Release WaveFunctionCollapse.csproj
```
Alternatively, use build instructions from the community for various platforms from the [relevant issue](https://github.com/mxgmn/WaveFunctionCollapse/issues/3). Casey Marshall made a [pull request](https://github.com/mxgmn/WaveFunctionCollapse/pull/18) that makes using the program with the command line more convenient and includes snap packaging.

Expand Down Expand Up @@ -178,6 +178,6 @@ that the resulting observed zone is navigable at each step.
* DeepMind open-ended learning team [used](https://storage.googleapis.com/deepmind-media/papers/Open-Ended%20Learning%20Leads%20to%20Generally%20Capable%20Agents/open-ended-learning-paper.pdf) WFC to generate arenas for reinforcement learning agents.

## Credits
Some samples are taken from the games Ultima IV and [Dungeon Crawl Stone Soup](https://github.com/crawl/crawl). Circles tileset is taken from [Mario Klingemann](https://twitter.com/quasimondo/status/778196128957403136). FloorPlan tileset is taken from [Lingdong Huang](https://github.com/LingDong-/ndwfc). Idea of generating integrated circuits was suggested to me by [Moonasaur](https://twitter.com/Moonasaur/status/759890746350731264) and their style was taken from Zachtronics' [Ruckingenur II](http://www.zachtronics.com/ruckingenur-ii/). Cat overlapping sample is taken from the Nyan Cat video, Qud sample was made by Brian Bucklew, MagicOffice + Spirals samples - by rid5x, ColoredCity + Link + Link 2 + Mazelike + RedDot + SmileCity samples - by Arvi Teikari, Wall sample - by Arcaniax, NotKnot + Sand + Wrinkles samples - by Krystian Samp. Summer tileset was made by Hermann Hillmann. Voxel models were rendered in [MagicaVoxel](http://ephtracy.github.io/).
Circles tileset is taken from [Mario Klingemann](https://twitter.com/quasimondo/status/778196128957403136). FloorPlan tileset is taken from [Lingdong Huang](https://github.com/LingDong-/ndwfc). Summer tiles were drawn by Hermann Hillmann. Cat overlapping sample is taken from the Nyan Cat video, Water + Forest + Mountains samples are taken from Ultima IV, 3Bricks sample is taken from Dungeon Crawl Stone Soup, Qud sample was made by Brian Bucklew, MagicOffice + Spirals samples - by rid5x, ColoredCity + Link + Link 2 + Mazelike + RedDot + SmileCity samples - by Arvi Teikari, Wall sample - by Arcaniax, NotKnot + Sand + Wrinkles samples - by Krystian Samp, Circle sample - by Noah Buddy. The rest of the examples and tilesets were made by me. Idea of generating integrated circuits was suggested to me by [Moonasaur](https://twitter.com/Moonasaur/status/759890746350731264) and their style was taken from Zachtronics' [Ruckingenur II](http://www.zachtronics.com/ruckingenur-ii/). Voxel models were rendered in [MagicaVoxel](http://ephtracy.github.io/).
<p align="center"><img alt="second collage" src="images/wfc-2.png"></p>
<p align="center"><img alt="voxel perspective" src="images/castle-3d.png"></p>
2 changes: 1 addition & 1 deletion SimpleTiledModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public override Bitmap Graphics()
Bitmap result = new Bitmap(MX * tilesize, MY * tilesize);
int[] bitmapData = new int[result.Height * result.Width];

if (NextUnobservedNode() < 0)
if (observed[0] >= 0)
{
for (int x = 0; x < MX; x++) for (int y = 0; y < MY; y++)
{
Expand Down
10 changes: 8 additions & 2 deletions samples.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,15 @@
<overlapping name="Sand" N="3" periodic="True" periodicInput="False" screenshots="3"/>
<overlapping name="Wrinkles" N="3" periodic="True" heuristic="MRV" size="120"/>
<overlapping name="3Bricks" N="3" symmetry="1" periodic="True"/>
<overlapping name="Circle" N="3" symmetry="1" periodic="True" heuristic="MRV" size="90" screenshots="1"/>
<overlapping name="Circle" N="4" symmetry="1" periodic="True" heuristic="MRV" size="90" screenshots="1"/>
<overlapping name="Disk" N="3" symmetry="1" periodic="True" heuristic="MRV" size="90" screenshots="1"/>
<overlapping name="Disk" N="3" periodic="True" heuristic="MRV" size="90" screenshots="1"/>
<overlapping name="Disk" N="4" periodic="True" heuristic="MRV" size="90" screenshots="1"/>
<overlapping name="Font" N="4" symmetry="1" heuristic="MRV" size="90"/>

<overlapping name="Village" N="3" symmetry="2" periodic="True" limit="50"/>
<simpletiled name="Summer" size="15" periodic="False" limit="15"/>
<overlapping name="Village" N="3" symmetry="2" size="36" periodic="True" limit="50"/>
<simpletiled name="Summer" size="10" periodic="False" limit="15"/>

<simpletiled name="Knots" subset="Standard" size="5" periodic="True" textOutput="True"/>
<simpletiled name="Summer" size="6" periodic="False" textOutput="True"/>
Expand Down
Binary file added samples/Circle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added samples/Disk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added samples/Font.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8bbf089

Please sign in to comment.