From 83baec368b8b6e7df911aa13a378ec614dbcde54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Teuli=C3=A8re?= Date: Wed, 16 Jan 2013 15:51:09 +0100 Subject: [PATCH] Topping: give the score penalty directly with the player move. This commit also adds a setting to disable the elapsed-time penalty. --- game/move.cpp | 4 ++-- game/move.h | 2 +- game/public_game.cpp | 4 ++-- game/public_game.h | 2 +- game/settings.cpp | 8 +++++++- game/topping.cpp | 29 ++++++++++++++++++----------- game/topping.h | 2 +- qt/prefs_dialog.cpp | 5 +++++ qt/stats_widget.cpp | 9 +++++---- qt/topping_widget.cpp | 2 +- qt/ui/prefs_dialog.ui | 17 ++++++++++++----- 11 files changed, 55 insertions(+), 29 deletions(-) diff --git a/game/move.cpp b/game/move.cpp index 67fe724..55d09b4 100644 --- a/game/move.cpp +++ b/game/move.cpp @@ -33,8 +33,8 @@ INIT_LOGGER(game, Move); -Move::Move() - :m_score(0) +Move::Move(int iPoints) + :m_score(iPoints) { m_type = NO_MOVE; } diff --git a/game/move.h b/game/move.h index 5fd3a46..f6078dc 100644 --- a/game/move.h +++ b/game/move.h @@ -50,7 +50,7 @@ class Move /** * Default constructor, corresponding to no move */ - Move(); + Move(int iPoints = 0); /** * Constructor taking a (valid) round diff --git a/game/public_game.cpp b/game/public_game.cpp index a514585..f83b29b 100644 --- a/game/public_game.cpp +++ b/game/public_game.cpp @@ -262,9 +262,9 @@ void PublicGame::toppingPlay(const wstring &iWord, const wstring &iCoord, int iE } -void PublicGame::toppingTimeOut() +void PublicGame::toppingTimeOut(int iElapsed) { - getTypedGame(m_game).turnTimeOut(); + getTypedGame(m_game).turnTimeOut(iElapsed); } diff --git a/game/public_game.h b/game/public_game.h index 18de318..3f94256 100644 --- a/game/public_game.h +++ b/game/public_game.h @@ -226,7 +226,7 @@ public: void toppingPlay(const wstring &iWord, const wstring &iCoord, int iElapsed); - void toppingTimeOut(); + void toppingTimeOut(int iElapsed); void toppingAddPenalty(int iPenalty); diff --git a/game/settings.cpp b/game/settings.cpp index 689ae85..3e7d0b5 100644 --- a/game/settings.cpp +++ b/game/settings.cpp @@ -255,6 +255,11 @@ Settings::Settings() // ============== Topping mode options ============== Setting &topping = m_conf->getRoot().add("topping", Setting::TypeGroup); + // If true, a score penalty equal to the number of elapsed seconds + // is given to the player at each turn + topping.add("elapsed-penalty", Setting::TypeBoolean) = true; + + // Additional penalty points given to the player when the timer expires topping.add("timeout-penalty", Setting::TypeInt) = 60; // Try to read the values from the configuration file @@ -277,6 +282,7 @@ Settings::Settings() copySetting(tmpConf, *m_conf, "arbitration.solo-value"); copySetting(tmpConf, *m_conf, "arbitration.penalty-value"); copySetting(tmpConf, *m_conf, "arbitration.warnings-limit"); + copySetting(tmpConf, *m_conf, "topping.elapsed-penalty"); copySetting(tmpConf, *m_conf, "topping.timeout-penalty"); } catch (const std::exception &e) @@ -371,7 +377,7 @@ int Settings::getInt(const string &iName) const return 5; else if (iName == "arbitration.warnings-limit") return 3; - else if (iName == "arbitration.timeout-penalty") + else if (iName == "topping.timeout-penalty") return 60; return 0; #endif diff --git a/game/topping.cpp b/game/topping.cpp index 9072a59..2fb39d3 100644 --- a/game/topping.cpp +++ b/game/topping.cpp @@ -115,21 +115,24 @@ void Topping::tryWord(const wstring &iWord, const wstring &iCoord, int iElapsed) } -void Topping::turnTimeOut() +void Topping::turnTimeOut(int iElapsed) { LOG_INFO("Timeout reached, finishing turn automatically"); m_board.removeTestRound(); - // The player didn't find the move - Command *pCmd = new PlayerMoveCmd(*m_players[m_currPlayer], Move()); - accessNavigation().addAndExecute(pCmd); + // Retrieve some settings + bool giveElapsedPenalty = Settings::Instance().getBool("topping.elapsed-penalty"); + int timeoutPenalty = Settings::Instance().getInt("topping.timeout-penalty"); - // Give a penalty to the player - // XXX: should we give the penalty directly in the NO_MOVE move? - int penalty = Settings::Instance().getInt("topping.timeout-penalty"); - if (penalty > 0) - addPenalty(penalty); + // Compute the points to give to the player + int points = timeoutPenalty; + if (giveElapsedPenalty) + points += iElapsed; + + // The player didn't find the move + Command *pCmd = new PlayerMoveCmd(*m_players[m_currPlayer], Move(points)); + accessNavigation().addAndExecute(pCmd); // Next turn endTurn(); @@ -155,10 +158,14 @@ int Topping::play(const wstring &, const wstring &) void Topping::recordPlayerMove(const Move &iMove, Player &ioPlayer, int iElapsed) { + // Compute the penalty points to give to the player + bool giveElapsedPenalty = Settings::Instance().getBool("topping.elapsed-penalty"); + int points = giveElapsedPenalty ? iElapsed : 0; + ASSERT(iMove.isValid(), "Only valid rounds should be played"); - // Modify the score of the given move, to be the elapsed time + // Modify the score of the given move, to be the computed score Round copyRound = iMove.getRound(); - copyRound.setPoints(iElapsed); + copyRound.setPoints(points); Move newMove(copyRound); // Update the rack and the score of the current player diff --git a/game/topping.h b/game/topping.h index 1c6d66f..bac8011 100644 --- a/game/topping.h +++ b/game/topping.h @@ -82,7 +82,7 @@ public: * This will play the top on the board, give a points penalty to the player * and start the next turn. */ - void turnTimeOut(); + void turnTimeOut(int iElapsed); /** * Give an additional penalty to the player (probably because diff --git a/qt/prefs_dialog.cpp b/qt/prefs_dialog.cpp index cb389ac..b2f4422 100644 --- a/qt/prefs_dialog.cpp +++ b/qt/prefs_dialog.cpp @@ -101,6 +101,8 @@ PrefsDialog::PrefsDialog(QWidget *iParent) spinBoxArbitSearchLimit->setToolTip(spinBoxTrainSearchLimit->toolTip()); spinBoxArbitWarnLimit->setToolTip(_q("Maximal number of \"acceptable\" warnings.\n" "Any additional warning will give a penalty to the player.")); + checkBoxToppingElapsedPenalty->setToolTip(_q("If checked, the player gets, at each turn, a score penalty\n" + "equal to the elapsed time for the turn.")); spinBoxToppingExpPenalty->setToolTip(_q("Number of points added to the player score when the timer expires.\n" "Set it to 0 if you don't want any penalty.")); @@ -162,6 +164,7 @@ PrefsDialog::PrefsDialog(QWidget *iParent) spinBoxArbitSearchLimit->setValue(Settings::Instance().getInt("arbitration.search-limit")); // Topping settings + checkBoxToppingElapsedPenalty->setChecked(Settings::Instance().getBool("topping.elapsed-penalty")); spinBoxToppingExpPenalty->setValue(Settings::Instance().getInt("topping.timeout-penalty")); // Confirmations @@ -297,6 +300,8 @@ void PrefsDialog::updateSettings() spinBoxArbitWarnLimit->value()); // Topping settings + Settings::Instance().setBool("topping.elapsed-penalty", + checkBoxToppingElapsedPenalty->isChecked()); Settings::Instance().setInt("topping.timeout-penalty", spinBoxToppingExpPenalty->value()); diff --git a/qt/stats_widget.cpp b/qt/stats_widget.cpp index e67c99b..18b4a57 100644 --- a/qt/stats_widget.cpp +++ b/qt/stats_widget.cpp @@ -378,11 +378,12 @@ void StatsWidget::setModelTurnData(const QModelIndex &iIndex, const TurnData &iTurn, const TurnData &iGameTurn) { // Set the text (score for the turn) - if (!iTurn.getMove().isNull()) + int score = iTurn.getMove().getScore(); + if (score != 0) { - int score = iTurn.getMove().getScore(); - setModelText(iIndex, QVariant(score), - score >= iGameTurn.getMove().getScore()); + bool shouldUseBold = score >= iGameTurn.getMove().getScore() + && (m_game == 0 || m_game->getMode() != PublicGame::kTOPPING); + setModelText(iIndex, QVariant(score), shouldUseBold); } // Set the background color diff --git a/qt/topping_widget.cpp b/qt/topping_widget.cpp index e5f0bbe..01ac865 100644 --- a/qt/topping_widget.cpp +++ b/qt/topping_widget.cpp @@ -254,7 +254,7 @@ void ToppingWidget::timeoutPenalty() .arg(move.getScore())); // End the turn - m_game->toppingTimeOut(); + m_game->toppingTimeOut(m_timerModel->getTotalDuration()); emit gameUpdated(); } diff --git a/qt/ui/prefs_dialog.ui b/qt/ui/prefs_dialog.ui index f4b4a12..c297a69 100644 --- a/qt/ui/prefs_dialog.ui +++ b/qt/ui/prefs_dialog.ui @@ -7,7 +7,7 @@ 0 0 474 - 699 + 737 @@ -495,14 +495,14 @@ _("Topping mode") - + - _("Additional penalty given when the timer expires:" + _("Additional penalty given when the timer expires:") - + 9999 @@ -512,7 +512,14 @@ - + + + + _("Give a 1 point penalty for each elapsed second") + + + + Qt::Horizontal