runar-rkmedia / gotally

0 stars 1 forks source link

Undo and Hint does not work correctly for randomized/infinite games #27

Closed runar-rkmedia closed 1 year ago

runar-rkmedia commented 1 year ago

Investigation needed. Looks like it is related to the compaction of the instruction/replay

Api-response on failed hint:

2023-05-18T14:31:33+02:00 ERR api/middleware.go:184 > Outgoing response content-type=application/proto errorDetails="{\"code\":\"internal\",\"message\":\"failed to map instructions: \\u0026errors.errorString{s:\\\"failed to resolve instruction L;D;R;L;R;L;R;R;D;13,14,19;Z;U;12,13,14;L;R;D;R;21,22;U;U;R;U;1,0,5;U;L;R;U;D;D;18,13;L;U;6,5;23,22,21;11,16,17;1,2,3,4;13,18,19,24;8,9,4;U;14,9,4; tallylogic.CompactHistory{c:triplets.CompactTriplets{0xb1, 0xd7, 0x5b, 0x80, 0xd3, 0x8a, 0x40, 0xc3, 0x6b, 0x8c, 0x2b, 0x52, 0x6b, 0x17, 0x95, 0x6a, 0x40, 0x94, 0xab, 0x6e, 0x17, 0x7c, 0x16, 0xae, 0x24, 0xd0, 0x6a, 0x38, 0x10, 0x62, 0x7, 0x8}, gameRows:5, gameColumns:5, bitsUsedForPathIndex:5, tripletsUsedForPathIndex:2}\\\"}\"}" label=request method=POST path=/tally.v1.BoardService/GetHint reqId=8YIJV8CufuE0PK-lPPr2W statusCode=500
runar-rkmedia commented 1 year ago

This was mostly due to Undo (game.go) not setting the seed and state for the randomizer. This caused inconsistencies for games that used the seed. A test for this case has now been added.

runar-rkmedia commented 1 year ago

Resetting the seed and state for randomized games are a bit more complicated. I'm thinking of ways to simplify this.

Currently, the game can be started with an initial seed. For randomized games, this seed is used at the start to generate the first cells from an empty board. the boardAtStart-property is set after the cells have been generated.

Perhaps we could move setting the boardAtStart to an earlier stage. This probably means that for randomized games, it will be an all empty board, and for challenge-games, it will always equal the template. By this logic, we can simply remove the whole property, and recreate the starting-board based on the rules and template.

runar-rkmedia commented 1 year ago

There are actually a few properties that affect this:

runar-rkmedia commented 1 year ago

Should have been solved now, in one of the later changes. If I remember correctly, this was fixed in b324a9210ebed8fd7b92ded301ad347e78b2585d where the hash for a rule did not take into account every parameter. I've now added a test with reflection that should ensure that even as more fields are added, the hash of the id should include those new fields.

I've also thought about changing the structure of rules, to be a very much smaller structure, but I don't think it matters.