Arbitration: by convention, use negative values to indicate a penalty

This commit is contained in:
Olivier Teulière 2012-04-30 08:31:34 +02:00
parent 6c16f203a5
commit e6c1a180c8
4 changed files with 13 additions and 9 deletions

View file

@ -139,6 +139,7 @@ bool Arbitration::hasWarning(unsigned iPlayerId) const
void Arbitration::addPenalty(unsigned iPlayerId, int iPoints)
{
ASSERT(iPlayerId < getNPlayers(), "Wrong player number");
ASSERT(iPoints >= 0, "Expected a positive value for the penalty");
if (iPoints == 0)
{
@ -147,6 +148,9 @@ void Arbitration::addPenalty(unsigned iPlayerId, int iPoints)
}
LOG_INFO("Giving a penalty of " << iPoints << " to player " << iPlayerId);
// By convention, use negative values to indicate a penalty
iPoints = -iPoints;
// If an existing penalty exists, merge it with the new one
const PlayerEventCmd *cmd = getPlayerEvent(iPlayerId, PlayerEventCmd::PENALTY);
if (cmd == 0)

View file

@ -31,8 +31,8 @@ INIT_LOGGER(game, PlayerEventCmd);
PlayerEventCmd::PlayerEventCmd(Player &ioPlayer, EventType iEvent, int iPoints)
: m_player(ioPlayer), m_eventType(iEvent), m_points(iPoints)
{
// This check is valid for the 3 event types
ASSERT(iPoints >= 0, "Negative points not allowed");
ASSERT(iEvent == PENALTY || iPoints >= 0, "Negative points not allowed");
ASSERT(iEvent != PENALTY || iPoints <= 0, "Positive points not allowed");
}

View file

@ -50,16 +50,16 @@ public:
void setMove(const Move& iMove) { m_move = iMove; }
// Setters for warnings, penalties and solos
void addWarning(unsigned iNb = 1) { m_warningsNb += iNb; }
void addPenaltyPoints(unsigned iPoints) { m_penaltyPoints += iPoints; }
void addSoloPoints(unsigned iPoints) { m_soloPoints += iPoints; }
void addPenaltyPoints(int iPoints) { m_penaltyPoints += iPoints; }
void addSoloPoints(int iPoints) { m_soloPoints += iPoints; }
unsigned int getPlayer() const { return m_playerId; }
const PlayedRack& getPlayedRack() const { return m_pldrack; }
const Move& getMove() const { return m_move; }
// Getters for warnings, penalties and solos
unsigned getWarningsNb() const { return m_warningsNb; }
unsigned getPenaltyPoints() const { return m_penaltyPoints; }
unsigned getSoloPoints() const { return m_soloPoints; }
int getPenaltyPoints() const { return m_penaltyPoints; }
int getSoloPoints() const { return m_soloPoints; }
wstring toString() const;

View file

@ -224,15 +224,15 @@ void HistoryWidget::updateModel()
}
// Set warnings, penalties and solos
if (t.getWarningsNb() > 0)
if (t.getWarningsNb() != 0)
{
m_model->setData(m_model->index(rowNum, m_colWarning), t.getWarningsNb());
}
if (t.getPenaltyPoints() > 0)
if (t.getPenaltyPoints() != 0)
{
m_model->setData(m_model->index(rowNum, m_colPenalty), t.getPenaltyPoints());
}
if (t.getSoloPoints() > 0)
if (t.getSoloPoints() != 0)
{
m_model->setData(m_model->index(rowNum, m_colSolo), t.getSoloPoints());
}