From bea2be5f63999e51cdfc61eb7f171614418afbf9 Mon Sep 17 00:00:00 2001 From: ItsDrike Date: Sat, 7 Dec 2024 20:46:39 +0100 Subject: [PATCH] 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. --- src/gamestate.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/gamestate.cpp b/src/gamestate.cpp index a36c6b2..9fe3e6e 100644 --- a/src/gamestate.cpp +++ b/src/gamestate.cpp @@ -451,8 +451,10 @@ QString GameState::generateStateHash() const { stateHash += slot->isRevealed() ? "t" : "f"; stateHash += ","; } - stateHash.removeLast(); - stateHash += " "; + + if (stateHash.last(1) != "|") + stateHash.removeLast(); + stateHash += "|"; } stateHash.removeLast(); @@ -462,8 +464,9 @@ QString GameState::generateStateHash() const { for (const PlayingCard* card : foundationPile) { stateHash += QString::number(card->value()) + "." + QString::number(card->suit()) + ","; } - stateHash.removeLast(); - stateHash += " "; + if (stateHash.last(1) != "|") + stateHash.removeLast(); + stateHash += "|"; } stateHash.removeLast();