From e6c1a180c86084c77bd18531e31f906e4ca4e452 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Teuli=C3=A8re?= Date: Mon, 30 Apr 2012 08:31:34 +0200 Subject: [PATCH] Arbitration: by convention, use negative values to indicate a penalty --- game/arbitration.cpp | 4 ++++ game/player_event_cmd.cpp | 4 ++-- game/turn.h | 8 ++++---- qt/history_widget.cpp | 6 +++--- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/game/arbitration.cpp b/game/arbitration.cpp index 5776447..f00aa8b 100644 --- a/game/arbitration.cpp +++ b/game/arbitration.cpp @@ -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) diff --git a/game/player_event_cmd.cpp b/game/player_event_cmd.cpp index 7043ea1..746632e 100644 --- a/game/player_event_cmd.cpp +++ b/game/player_event_cmd.cpp @@ -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"); } diff --git a/game/turn.h b/game/turn.h index d57ffc5..4e1c283 100644 --- a/game/turn.h +++ b/game/turn.h @@ -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; diff --git a/qt/history_widget.cpp b/qt/history_widget.cpp index 4aee6dd..11c9651 100644 --- a/qt/history_widget.cpp +++ b/qt/history_widget.cpp @@ -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()); }