summaryrefslogtreecommitdiff
path: root/quackleio/gcgio.cpp
diff options
context:
space:
mode:
authorJohn Fultz <jfultz@wolfram.com>2016-08-02 04:08:43 -0500
committerJohn Fultz <jfultz@wolfram.com>2016-08-02 06:37:15 -0500
commitdbcb13d3c87133117bc54023c162ad0a202efa1d (patch)
tree955715420b4584b73baa676c1b4b5fe4febb3c48 /quackleio/gcgio.cpp
parenta3aa3602d173939a2b616bb78a5a739eb9761d9b (diff)
Fixes to allow bad endgames to be loaded from GCGs.
Not perfect, but it now does a decent job of not corrupting GCGs when it loads one where players have messed up tile counts/drawing in the end-game. It also tries to annotate these for the player and in any GCG file that's round-tripped. Also, a lot of C++11-izing of ranged iterators.
Diffstat (limited to 'quackleio/gcgio.cpp')
-rw-r--r--quackleio/gcgio.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/quackleio/gcgio.cpp b/quackleio/gcgio.cpp
index 483678b..b60d57c 100644
--- a/quackleio/gcgio.cpp
+++ b/quackleio/gcgio.cpp
@@ -143,6 +143,7 @@ Quackle::Game *GCGIO::read(QTextStream &stream, int flags)
gameStarted = true;
}
+ UVString currentPlayer = Util::qstringToString(strings.front().mid(1, strings.front().size() - 2));
strings.pop_front();
if (strings.isEmpty())
@@ -158,10 +159,11 @@ Quackle::Game *GCGIO::read(QTextStream &stream, int flags)
if (rackString.startsWith("(") && rackString.endsWith(")"))
{
// end the game
- if (ret->hasPositions())
+ if (ret->hasPositions() && !ret->currentPosition().gameOver())
ret->commitCandidate(canMaintainCrosses);
else
ret->addPosition();
+ ret->currentPosition().setTileBonus(currentPlayer, Util::encode(rackString.mid(1, rackString.size() - 2)), strings.front().toInt());
continue;
}
@@ -359,11 +361,14 @@ void GCGIO::write(const Quackle::Game &game, QTextStream &stream)
outputScoreAddition = 0;
}
- stream << ">" << Util::uvStringToQString((*it).currentPlayer().abbreviatedName()) << ": " << Util::letterStringToQString((*it).currentPlayer().rack().alphaTiles()) << " " << Util::uvStringToQString(move.toString()) << " +" << outputScore << " " << outputScore + (*it).currentPlayer().score() << endl;
+ QString rackString = Util::letterStringToQString((*it).currentPlayer().rack().alphaTiles());
+ if (move.action == Quackle::Move::UnusedTilesBonusError)
+ rackString = QString();
+ stream << ">" << Util::uvStringToQString((*it).currentPlayer().abbreviatedName()) << ": " << rackString << " " << Util::uvStringToQString(move.toString()) << " +" << outputScore << " " << outputScore + (*it).currentPlayer().score() << endl;
if (move.isChallengedPhoney())
{
- stream << ">" << Util::uvStringToQString((*it).currentPlayer().abbreviatedName()) << ": " << Util::letterStringToQString((*it).currentPlayer().rack().alphaTiles()) << " -- -" << outputScore << " " << move.effectiveScore() + (*it).currentPlayer().score() << endl;
+ stream << ">" << Util::uvStringToQString((*it).currentPlayer().abbreviatedName()) << ": " << rackString << " -- -" << outputScore << " " << move.effectiveScore() + (*it).currentPlayer().score() << endl;
}
if (outputScoreAddition != 0)