Stats: display end game points for a free game

This commit is contained in:
Olivier Teulière 2012-10-05 18:19:06 +02:00
parent b53295c782
commit c700f39ac7
8 changed files with 49 additions and 17 deletions

View file

@ -163,6 +163,13 @@ void History::addSoloPoints(int iPoints)
} }
void History::addEndGamePoints(int iPoints)
{
ASSERT(m_history.size() > 1, "Too short history");
m_history[m_history.size() - 2]->addEndGamePoints(iPoints);
}
wstring History::toString() const wstring History::toString() const
{ {
wstring rs; wstring rs;

View file

@ -96,6 +96,8 @@ public:
void addSoloPoints(int iPoints); void addSoloPoints(int iPoints);
void addEndGamePoints(int iPoints);
/// String handling /// String handling
wstring toString() const; wstring toString() const;

View file

@ -127,9 +127,20 @@ int Player::getSoloPoints() const
} }
int Player::getEndGamePoints() const
{
int total = 0;
for (unsigned i = 0; i < m_history.getSize(); ++i)
{
total += m_history.getTurn(i).getEndGamePoints();
}
return total;
}
int Player::getTotalScore() const int Player::getTotalScore() const
{ {
return getPoints() + getSoloPoints() + getPenaltyPoints(); return m_score + getSoloPoints() + getPenaltyPoints() + getEndGamePoints();
} }

View file

@ -91,6 +91,9 @@ public:
/// Return the total number of solo points received /// Return the total number of solo points received
int getSoloPoints() const; int getSoloPoints() const;
/// Return the total number of end game points
int getEndGamePoints() const;
/// Return the total score of the player, including solos and penalties /// Return the total score of the player, including solos and penalties
int getTotalScore() const; int getTotalScore() const;
@ -100,7 +103,7 @@ public:
// Add (or remove, if iPoints is negative) points to the score // Add (or remove, if iPoints is negative) points to the score
// of the player // of the player
void addPoints(int iPoints) { m_score += iPoints; } void addPoints(int iPoints) { m_score += iPoints; }
int getPoints() const { return m_score; } int getPoints() const { return getTotalScore(); }
wstring toString() const; wstring toString() const;

View file

@ -47,7 +47,7 @@ void PlayerEventCmd::doExecute()
else if (m_eventType == SOLO) else if (m_eventType == SOLO)
m_player.accessHistory().addSoloPoints(m_points); m_player.accessHistory().addSoloPoints(m_points);
else if (m_eventType == END_GAME) else if (m_eventType == END_GAME)
m_player.addPoints(m_points); m_player.accessHistory().addEndGamePoints(m_points);
else else
ASSERT(false, "Missing case"); ASSERT(false, "Missing case");
} }
@ -62,7 +62,7 @@ void PlayerEventCmd::doUndo()
else if (m_eventType == SOLO) else if (m_eventType == SOLO)
m_player.accessHistory().addSoloPoints(- m_points); m_player.accessHistory().addSoloPoints(- m_points);
else if (m_eventType == END_GAME) else if (m_eventType == END_GAME)
m_player.addPoints(- m_points); m_player.accessHistory().addEndGamePoints(- m_points);
else else
ASSERT(false, "Missing case"); ASSERT(false, "Missing case");
} }

View file

@ -31,7 +31,7 @@ INIT_LOGGER(game, Turn);
// constructor completely // constructor completely
Turn::Turn() Turn::Turn()
: m_playerId(0), m_warningsNb(0), : m_playerId(0), m_warningsNb(0),
m_penaltyPoints(0), m_soloPoints(0) m_penaltyPoints(0), m_soloPoints(0), m_endGamePoints(0)
{ {
} }
@ -39,7 +39,7 @@ Turn::Turn()
Turn::Turn(unsigned int iPlayerId, const PlayedRack& iPldRack, Turn::Turn(unsigned int iPlayerId, const PlayedRack& iPldRack,
const Move& iMove) const Move& iMove)
: m_playerId(iPlayerId), m_pldrack(iPldRack), m_move(iMove), : m_playerId(iPlayerId), m_pldrack(iPldRack), m_move(iMove),
m_warningsNb(0), m_penaltyPoints(0), m_soloPoints(0) m_warningsNb(0), m_penaltyPoints(0), m_soloPoints(0), m_endGamePoints(0)
{ {
} }

View file

@ -48,18 +48,20 @@ public:
void setPlayer(unsigned int iPlayerId) { m_playerId = iPlayerId; } void setPlayer(unsigned int iPlayerId) { m_playerId = iPlayerId; }
void setPlayedRack(const PlayedRack& iPldRack) { m_pldrack = iPldRack; } void setPlayedRack(const PlayedRack& iPldRack) { m_pldrack = iPldRack; }
void setMove(const Move& iMove) { m_move = iMove; } void setMove(const Move& iMove) { m_move = iMove; }
// Setters for warnings, penalties and solos // Setters for events (warnings, penalties, solos, end game primes)
void addWarning(unsigned iNb = 1) { m_warningsNb += iNb; } void addWarning(unsigned iNb = 1) { m_warningsNb += iNb; }
void addPenaltyPoints(int iPoints) { m_penaltyPoints += iPoints; } void addPenaltyPoints(int iPoints) { m_penaltyPoints += iPoints; }
void addSoloPoints(int iPoints) { m_soloPoints += iPoints; } void addSoloPoints(int iPoints) { m_soloPoints += iPoints; }
void addEndGamePoints(int iPoints) { m_endGamePoints += iPoints; }
unsigned int getPlayer() const { return m_playerId; } unsigned int getPlayer() const { return m_playerId; }
const PlayedRack& getPlayedRack() const { return m_pldrack; } const PlayedRack& getPlayedRack() const { return m_pldrack; }
const Move& getMove() const { return m_move; } const Move& getMove() const { return m_move; }
// Getters for warnings, penalties and solos // Getters for events (warnings, penalties, solos, end game primes)
unsigned getWarningsNb() const { return m_warningsNb; } unsigned getWarningsNb() const { return m_warningsNb; }
int getPenaltyPoints() const { return m_penaltyPoints; } int getPenaltyPoints() const { return m_penaltyPoints; }
int getSoloPoints() const { return m_soloPoints; } int getSoloPoints() const { return m_soloPoints; }
int getEndGamePoints() const { return m_endGamePoints; }
wstring toString() const; wstring toString() const;
@ -70,6 +72,7 @@ private:
int m_warningsNb; int m_warningsNb;
int m_penaltyPoints; int m_penaltyPoints;
int m_soloPoints; int m_soloPoints;
int m_endGamePoints;
}; };
#endif #endif

View file

@ -90,11 +90,13 @@ void StatsWidget::refresh()
unsigned histSize = m_game == NULL ? 0 : m_game->getHistory().getSize(); unsigned histSize = m_game == NULL ? 0 : m_game->getHistory().getSize();
unsigned nbPlayers = m_game == NULL ? 0 : m_game->getNbPlayers(); unsigned nbPlayers = m_game == NULL ? 0 : m_game->getNbPlayers();
setModelSize(nbPlayers + 1, histSize + 9); setModelSize(nbPlayers + 1, histSize + 10);
// Some fields are displayed only in some cases // Some fields are displayed only in some cases
const bool isArbit = m_game != NULL && const bool isArbit = m_game != NULL &&
m_game->getParams().getMode() == GameParams::kARBITRATION; m_game->getParams().getMode() == GameParams::kARBITRATION;
const bool isFreeGame = m_game != NULL &&
m_game->getParams().getMode() == GameParams::kFREEGAME;
const bool canHaveSolos = m_game != NULL && const bool canHaveSolos = m_game != NULL &&
m_game->getParams().getMode() == GameParams::kDUPLICATE && m_game->getParams().getMode() == GameParams::kDUPLICATE &&
Settings::Instance().getInt("duplicate.solo-players") <= (int)m_game->getNbPlayers(); Settings::Instance().getInt("duplicate.solo-players") <= (int)m_game->getNbPlayers();
@ -107,8 +109,10 @@ void StatsWidget::refresh()
for (unsigned i = 1; i <= histSize; ++i) for (unsigned i = 1; i <= histSize; ++i)
setModelHeader(col++, QString("#%1").arg(i), false); setModelHeader(col++, QString("#%1").arg(i), false);
setSectionHidden(col, !isArbit && !canHaveSolos); setSectionHidden(col, !isArbit && !canHaveSolos && !isFreeGame);
setModelHeader(col++, _q("Sub-total"), false); setModelHeader(col++, _q("Sub-total"), false);
setSectionHidden(col, !isFreeGame);
setModelHeader(col++, _q("End game points"), false);
setSectionHidden(col, !isArbit && !canHaveSolos); setSectionHidden(col, !isArbit && !canHaveSolos);
setModelHeader(col++, _q("Solo points"), false); setModelHeader(col++, _q("Solo points"), false);
setSectionHidden(col, !isArbit); setSectionHidden(col, !isArbit);
@ -145,7 +149,7 @@ void StatsWidget::refresh()
} }
setModelText(getIndex(row, col++), score, true); setModelText(getIndex(row, col++), score, true);
// Skip the events columns // Skip the events columns
col += 3; col += 4;
setModelText(getIndex(row, col++), score, true); setModelText(getIndex(row, col++), score, true);
// Skip the diff column // Skip the diff column
++col; ++col;
@ -180,15 +184,15 @@ void StatsWidget::refresh()
setModelText(getIndex(i + 1, col++), score, score >= gameTotal); setModelText(getIndex(i + 1, col++), score, score >= gameTotal);
// Events columns // Events columns
for (int j = 0; j <= 2; ++j) for (int j = 0; j <= 3; ++j)
{ {
setModelEventData(getIndex(i + 1, col++), j, player); setModelEventData(getIndex(i + 1, col++), j, player);
} }
// Final score // Final score
score += player.getSoloPoints() + player.getPenaltyPoints(); score += player.getSoloPoints() + player.getPenaltyPoints() + player.getEndGamePoints();
setModelText(getIndex(i + 1, col++), score, score >= gameTotal); setModelText(getIndex(i + 1, col++), score, score >= gameTotal);
//ASSERT(score == player.getTotalScore(), "Invalid score computation"); ASSERT(score == player.getTotalScore(), "Invalid score computation");
// Diff with game total // Diff with game total
setModelText(getIndex(i + 1, col++), score - gameTotal); setModelText(getIndex(i + 1, col++), score - gameTotal);
@ -302,11 +306,13 @@ void StatsWidget::setModelEventData(const QModelIndex &iIndex,
int iEvent, const Player &iPlayer) int iEvent, const Player &iPlayer)
{ {
QVariant text; QVariant text;
if (iEvent == 0 && iPlayer.getSoloPoints() != 0) if (iEvent == 0 && iPlayer.getEndGamePoints() != 0)
text = iPlayer.getEndGamePoints();
else if (iEvent == 1 && iPlayer.getSoloPoints() != 0)
text = iPlayer.getSoloPoints(); text = iPlayer.getSoloPoints();
else if (iEvent == 1 && iPlayer.getPenaltyPoints() != 0) else if (iEvent == 2 && iPlayer.getPenaltyPoints() != 0)
text = iPlayer.getPenaltyPoints(); text = iPlayer.getPenaltyPoints();
else if (iEvent == 2 && iPlayer.getWarningsNb() != 0) else if (iEvent == 3 && iPlayer.getWarningsNb() != 0)
text = iPlayer.getWarningsNb(); text = iPlayer.getWarningsNb();
setModelText(iIndex, text); setModelText(iIndex, text);
} }