From b0d66b0c578a1845900aba0747f4c4a30ccf76b2 Mon Sep 17 00:00:00 2001 From: John Fultz Date: Sat, 16 Jul 2016 13:22:50 -0500 Subject: 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. --- game.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'game.cpp') diff --git a/game.cpp b/game.cpp index fca5942..c4d366e 100644 --- a/game.cpp +++ b/game.cpp @@ -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 -- cgit v1.2.3