From 2ec6206e260b93566de6e896442e0b413860d50c Mon Sep 17 00:00:00 2001 From: ItsDrike Date: Fri, 6 Dec 2024 17:01:17 +0100 Subject: [PATCH] Improve hash state computing The new logic avoids possible collisions that could previously occur. --- src/gamestate.cpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/gamestate.cpp b/src/gamestate.cpp index ddb1d11..61f609c 100644 --- a/src/gamestate.cpp +++ b/src/gamestate.cpp @@ -453,32 +453,47 @@ QString GameState::generateStateHash() const { // The repetition here is annoying, I know for (const auto& column : m_columns) { for (const ColumnSlot* slot : column) { - stateHash += QString::number(slot->card()->value()) + QString::number(slot->card()->suit()); + stateHash += QString::number(slot->card()->value()) + "." + QString::number(slot->card()->suit()); stateHash += slot->isRevealed() ? "t" : "f"; stateHash += ","; } + stateHash.removeLast(); + stateHash += " "; } + stateHash.removeLast(); + stateHash += " ; "; + for (const auto& foundationPile : m_foundation) { 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(); + stateHash += " "; } + stateHash.removeLast(); + stateHash += " ; "; + for (const PlayingCard* card : m_throwawayPile) { - stateHash += QString::number(card->value()) + QString::number(card->suit()) + ","; + stateHash += QString::number(card->value()) + "." + QString::number(card->suit()) + ","; } + stateHash.removeLast(); + stateHash += " ; "; + for (const PlayingCard* card : m_drawPile) { - stateHash += QString::number(card->value()) + QString::number(card->suit()) + ","; + stateHash += QString::number(card->value()) + "." + QString::number(card->suit()) + ","; } + stateHash.removeLast(); + stateHash += " ; "; + stateHash += m_gameWon ? "t" : "f"; return stateHash; } - bool GameState::tryAutoMoveSingleCard(PlayingCard& cardToMove, int skipColumnId) { // 1. Try moving the card to the foundation const int foundationId = static_cast(cardToMove.suit());