Improve hash state computing
The new logic avoids possible collisions that could previously occur.
This commit is contained in:
parent
5da97d7c0e
commit
2ec6206e26
|
@ -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());
|
||||
|
|
Loading…
Reference in a new issue