pietru2004 / Godot-WFC

My implementation of WFC algoritm with gui for making tile rules and 3 generators.
32 stars 1 forks source link

Calculation never ends. Errors have little information. #3

Closed RonYanDaik closed 1 year ago

RonYanDaik commented 1 year ago

Calculation does not end, How do i figure out what i did wrong? Picture: left - calculation , right - painted rules.

image

What do this errors mean? image

pietru2004 commented 1 year ago

the debug shows last cell that had 0 possible outcomes array: element 0 - position of cell element 1 shows arrays from surrounding cells (6 sides of cube) element 2 arrays that were used to compare cells

Also it works, but if you have many cells and small ruleset it will be harder...

try looking at demo - my way of doing stuff was clearing gridmap or editing what was generated when it was having problems and painting by hand and then adding rules with rule add mode.

pietru2004 commented 1 year ago

Depending on tile set and rules it can take from 57(small ammount) up to (undefined ammount, 4000+) of map generation errors. Try smaller map sizes - that are more likely to generate with no errors and make it easier to spot problems/rule problems Make Delay Between Tries bigger (seconds) Starter tiles are taken from mesh lib definer -> mesh lib data, so you do not need to regenerate rules for them Remember to check is your grass tile ignoring rotation, if it does not ignore rotation then well it can be source of problems

RonYanDaik commented 1 year ago

It got stuck again with this ruleset.

image It feels like it shouldn't have problem with this tileset. Every piece has ignore rotation = off

pietru2004 commented 1 year ago

it's problem is that straight road knows it can have grass z- straight does not know it can have road z+

pietru2004 commented 1 year ago

rule can be 2 tiles placed next to each other try placing somewhere grass - road - grass

RonYanDaik commented 1 year ago

Im not sure how its working, but, Maybe it will be a good idea to add sort of "safe mod" when algorithm will pick next cell with least amount of variants?

On Tue, Jul 25, 2023, 02:15 pietru2004 @.***> wrote:

it's problem is that straight road knows it can have grass z- straight does not know it can have road z+

— Reply to this email directly, view it on GitHub https://github.com/pietru2004/Godot-WFC/issues/3#issuecomment-1648746561, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAZR6RGJ35L5G7TZBHKTPATXR36X5ANCNFSM6AAAAAA2VT2KXY . You are receiving this because you authored the thread.Message ID: @.***>

pietru2004 commented 1 year ago

you can disable conflict_repair, if there is place where it can't place any cell it will stop running, as for safe mode... I can think about it, mayby make conflict repair conflict resolving with options stop running, skip, try repair...

also see this obraz it would resolve problems, but it would take some time... you could try setting delay to 0.001 or just 0 - run every frame, clear console, start generation, go mayby eat something (remembering to leave focus on godot, or it will slow engine running speed) and come back and hopefully have result...

RonYanDaik commented 1 year ago

Couple of observings. I've noticed persistent pattern. At some point at row 15 (its not an edge, area is 20x20) algorithm stops calculating diagonal and goes along red arrow which always leads to errors since 2 regions begin to fight each other. image

After that it starts to pick cells that will lead to the errors.

errors

If it would've picked blue ones that could be avoided. Also blue once should have less available options. image

Can you tell which part of code is responsible for deciding which cell to pick next?

RonYanDaik commented 1 year ago

it would resolve problems, but it would take some time...

No, it doesn't looks like it will. Its stuck in same one cell forever.

pietru2004 commented 1 year ago

It is supposed to select based on sorting of cells and take cell 0 from array...

RonYanDaik commented 1 year ago

With size of 16 it works fine. But when i set size to 17 almost it always breaks.

RonYanDaik commented 1 year ago

It is supposed to select based on sorting of cells and take cell 0 from array...

Is this it?

func sort_entropy(a, b):
    print ("a:",a, " b:",b)
    return (a[1] < b[1]) and !(a[1]<=0)
pietru2004 commented 1 year ago

now that I look at this I docalc entropy but I don't apply it anywhere... func calc_celc_entropy, seams I forgot to use data from entropy calc...

pietru2004 commented 1 year ago

please check new update - I was getting consistent 1 confilict repair... no more... (demo2) (demo1 was getting bit more cause area is 10 on 20)

RonYanDaik commented 1 year ago

Now it works better if i enable only one starter tile - green grass tile. If i have more enabled it gets stuck again. image

But now algorithm always go around first. Before it starts filling everything else. Which gives pretty similiar results. Which makes sense. It fills last row and since it has only 2 variants it pretty soon chooses end-of-road tile. And at that point its "locked" with the result.

I liked more previous behavior calculating in diagonals. Which game more variety in results. image

wfc1

RonYanDaik commented 1 year ago

But here is waht happens when it goes "other" direction.

wfc2

It pick red position. Whit is already an error. Instead it should've picked one of the blues. image

It looks like you are calculating entropy only for adjacent tiles and do not propagate potential changes along the grid. Which leads to errors.

In other world you skip step of recalculating the entropy of the entire grid after placing a single tile.

RonYanDaik commented 1 year ago

In other world you skip step of recalculating the entropy of the entire grid after placing a single tile.

Recalculating entire grid seems time consuming, but also is repairing of errors. that leads to mote time consuming calculation. Also you don't need to recalculate full grid, only those cells that are changing. It should lead to narrowing it to only 10% of grid recalculation.

pietru2004 commented 1 year ago

it works on adding waiting tiles - it adds starter tile to waiting tiles, selects it and adds tiles that are on the sides, it favours side where is 1 tile or tile weight is higher, that is theory so if you have [1,1] and [3,1] the [3,1] should have lower entropy and be used first

this obraz gives this obraz

mayby I should add check to get list of tiles with the same entropy and get random from them, and not always cell 0 from array

pietru2004 commented 1 year ago

please try new demo_road_line - it is made to be similar with tile set you chose, also for your usecase I recomend t ocheck new cell sorting obraz

pietru2004 commented 1 year ago

@RonYanDaik I want to ask is the generator working now... If yes I will close issue...

RonYanDaik commented 1 year ago

For this case it works better. Yes.