#Wave function collapse, avoiding disconnected pieces

1 messages · Page 1 of 1 (latest)

hushed meteor
neon lynx
#

That's tricky. I recently did my own implementation of WFC, so hopefully I can help.

Fundamentally, the algorithm in it's most basic form does not keep track of what you're hoping to keep track of. That is, when the algorithm is working correctly, an "isolated" road is considered legal, but you want that not to happen.

I ran into a similar issue where my tileset was so complicated that it was possible for blank spots to be surrounded by incompatible tiles so that there was no legal solution for the blank slot. I think you could apply the same solution to your problem:

What I did was when I realized a tile was "impossible", I reset that tile and all adjacent tiles back to un-collapsed form, so that they were unknown/blank again. Then I simply let it continue, and since it had a remedy and could keep applying it whenever it got stuck, it would eventually patch itself up.

I would try something similar with your problem. Draw your map, then run a quick function to check for isolated paths. One way of doing that would be to find every "endpoint" on your map, and check what they're connected to. If they're only connected to "straights" and "turns" but no "intersections" you know it's an isolated path.

Once you've found your problems, remove them from your map and make your code re-fill in those blanks. Eventually it should figure it out.

hushed meteor
#

Thanks for the advice! :) and apologies for the late reply! 😬 had a busy day in work and then the work christmas party afterwards

But yeah I also asked in a game dev server and someone suggested removing the dead end tile and it should then very rarely occur only in the case of 4 corners connected to a loop, once way to solve that is as you suggested recheck the map after its generated, but another thing could be to also check the diagonals as well as the adjacent and it should avoid the issue completely, this only works though since I have a very simple tile set.

neon lynx
#

No problem! Let me know any other issues you run in to!