diff options
author | John Fultz <jfultz@wolfram.com> | 2016-07-16 13:22:50 -0500 |
---|---|---|
committer | John Fultz <jfultz@wolfram.com> | 2016-07-16 13:23:24 -0500 |
commit | b0d66b0c578a1845900aba0747f4c4a30ccf76b2 (patch) | |
tree | f343566a5687b90a17f4f46aabebc425b518969b /game.cpp | |
parent | bdde000cec5bd092168bb6613109b3d6dbe6b52a (diff) |
Fix regressions in end-game tile management.
My end-game management was working fine for the case
I had been trying most...unknown racks and blind exchanges.
But I forgot to prevent regular exchanges from depleting the
overall tile counts. And I didn't realize that this code might
be called with a clipped history, due to the way that the
computer players can clone game boards for simulations.
I think this fixes all of the problems I introduced, while keeping
the endgame tile counts correct in the unknown racks case.
Diffstat (limited to 'game.cpp')
-rw-r--r-- | game.cpp | 19 |
1 files changed, 12 insertions, 7 deletions
@@ -779,12 +779,12 @@ bool GamePosition::incrementTurn(const History* history) const Quackle::PositionList positions(history->positionsFacedBy((*nextCurrentPlayer).id())); if (positions.size() > 0) m_tilesOnRack = positions.back().m_tilesOnRack; - m_tilesOnRack -= m_moveMade.usedTiles().size(); - while (m_tilesInBag > 0 && m_tilesOnRack < QUACKLE_PARAMETERS->rackSize()) - { - m_tilesInBag--; - m_tilesOnRack++; - } + else + // note...this can happen not just at the beginning of a game, but inside of a simming player engine + // which doesn't have a full history list + m_tilesOnRack = currentPlayer().rack().tiles().size(); + if (m_moveMade.action == Move::Place) + m_tilesOnRack -= m_moveMade.usedTiles().size(); if (m_tilesInBag == 0) { // We can get off on our counting with unknown racks. @@ -798,7 +798,7 @@ bool GamePosition::incrementTurn(const History* history) else if (m_tilesOnRack != 0 && remainingRack.empty()) { int tilesToMove = m_tilesOnRack; - while (otherPlayerRack.tiles().size() > 0 && tilesToMove > 0) + while (otherPlayerRack.tiles().size() > 0 && tilesToMove-- > 0) { LetterString oneAtATime = otherPlayerRack.tiles().substr(0, 1); otherPlayerRack.unload(oneAtATime); @@ -807,6 +807,11 @@ bool GamePosition::incrementTurn(const History* history) } nextCurrentPlayer->setRack(otherPlayerRack); } + while (m_tilesInBag > 0 && m_tilesOnRack < QUACKLE_PARAMETERS->rackSize() && m_moveMade.action == Move::Place) + { + m_tilesInBag--; + m_tilesOnRack++; + } } // update our current player's score before possibly |