BorisTheBrave / DeBroglie

DeBroglie is a C# library implementing the Wave Function Collapse algorithm with support for additional non-local constraints, and other useful features.
https://boristhebrave.github.io/DeBroglie/
MIT License
456 stars 37 forks source link

Negative adjacency rule? #18

Open TheAtomAnt opened 3 years ago

TheAtomAnt commented 3 years ago

While exploring this tool I was not yet able to find a 'negative' adjacency rule. I realize that simply not defining a rule would potentially cause it to not apply but in my case I'm not seeing a way to deal with an issue.

            var tile1 = new Tile("█");
            var tile2 = new Tile(" ");

            var model = new AdjacentModel(directions: DirectionSet.Cartesian2d);
            var tiles = new[] { tile1, tile2 };

            model.AddAdjacency(tiles, tiles, 1, 0, 0);
            model.AddAdjacency(tiles, tiles, 0, 1, 0);

            model.SetFrequency(tile1, 1);
            model.SetFrequency(tile2, .25);

What I'd like to see is a way to disable diagonal directions. Not sure if this is possible with the way the adjacency system is designed but I'll continue exploring. Currently I'm building a quick and dirty constraint to deal with this - though extending the connected constraint might be the better way to go.

Just wondering about the adjacency system and if I'm missing a negative rule, or the ability to remove a previously configured rule.

BorisTheBrave commented 3 years ago

I had intended that you just don't add adjacencies you don't want.

In any case, adjacency model only looks ad direct adjacencies, not diagonals, so it won't do what you want. For diagonals, you'd either need to use the overlapping model, or use a custom topology where each tile is adjacent to 8 others.