godot-constraint-solving
godot-constraint-solving copied to clipboard
Generator doesn't infer rules from sample
I just started fiddling around with the generator searching for some samples to use on my project (as I'm building a simple 2D dungeon generator I only need to determine whether a cell is a wall or a floor). I have only a WFC2DGenerator node along with a sample tilemap and a target tilemap. My tileset is composed of only two tiles, like the dungeon example in this repository. While technically the algorithm works, it just seems to place random tiles scattered and when I flag "Print rules" it just prints the same rules (they are the same in respect to all patterns). I don't understand why, since I expect similar result to the ones listed here.
Is there something else I need to do other than linking the tilemaps nodes into the generator one or is it a bug?
Hi.
The example from orifinal WFC repo you mentioned either uses 3x3 pixel fragments as tiles (or uses a bit more complex constraints, I'm not exactly sure how exactly it works).
This addon by default works with single tiles, so in your case:
- there are 2 types of tiles - white and black
- the algorithm learns that to the left from white tile there may be a white tile or a black tile and to the left of a black tile there may be a black tile or white tile from sample.
- (the same goes for below/above)
that's exactly what the printed rules show:
(
(1,1,),
(1,1,),
)
in this matrix each row and each column correspond to a tile type, so in your case it's 2x2 matrix.
mth cell in nth row contains 1 if a tile of type n can be placed to the left (or below for Y axis matrix) of a tile of type m and 0 if it can not.
So, matrix of all 1s means that all combinations of tiles are allowed.
And a randomly filled target map is kinda an expected behavior in this case.
In order to achieve a more useful result, you may use larger tiles, each containing a certain pattern of NxM, e.g. 3x3 pixels. Or you can use a multitlile mapper to interpret each NxM rect of your maps as a separate tile, like it's done in this example (I just noticed that it's placed in a wrong folder). Note that most likely, you'll have to provide samples with different offsets as the mapper will recognize patterns only if they are aligned to the grid.
Also, I think, the problem can be summarized to the following rule:
A tile should represent a structure, not a material.
I.e. not just "a wall" but "an eastern wall", "an east-south inner corner of a wall", etc.