Improve hash state computing

The new logic avoids possible collisions that could previously occur.
This commit is contained in:
ItsDrike 2024-12-06 17:01:17 +01:00
parent 5da97d7c0e
commit 2ec6206e26
Signed by: ItsDrike
GPG key ID: FA2745890B7048C0

View file

@ -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<int>(cardToMove.suit());