bug: Fix state hash for empty piles

The current implementation of state hash doesn't represent empty columns
or foundations properly. This leads to a potential collision if there is
a full column next to an empty column, as it's indistinguishable which
column the data lies on. (In practice, this can't happen for
foundations, as they only hold cards of distinct types, so the collision
only occurs with columns.)

This commit fixes the issue and makes sure to represent empty piles
properly.
This commit is contained in:
ItsDrike 2024-12-07 20:46:39 +01:00
parent 985e99cf77
commit bea2be5f63
Signed by: ItsDrike
GPG key ID: FA2745890B7048C0

View file

@ -451,8 +451,10 @@ QString GameState::generateStateHash() const {
stateHash += slot->isRevealed() ? "t" : "f"; stateHash += slot->isRevealed() ? "t" : "f";
stateHash += ","; stateHash += ",";
} }
stateHash.removeLast();
stateHash += " "; if (stateHash.last(1) != "|")
stateHash.removeLast();
stateHash += "|";
} }
stateHash.removeLast(); stateHash.removeLast();
@ -462,8 +464,9 @@ QString GameState::generateStateHash() const {
for (const PlayingCard* card : foundationPile) { for (const PlayingCard* card : foundationPile) {
stateHash += QString::number(card->value()) + "." + QString::number(card->suit()) + ","; stateHash += QString::number(card->value()) + "." + QString::number(card->suit()) + ",";
} }
stateHash.removeLast(); if (stateHash.last(1) != "|")
stateHash += " "; stateHash.removeLast();
stateHash += "|";
} }
stateHash.removeLast(); stateHash.removeLast();