mirror of
git://git.savannah.nongnu.org/eliot.git
synced 2025-01-18 10:26:15 +01:00
Topping: give the score penalty directly with the player move.
This commit also adds a setting to disable the elapsed-time penalty.
This commit is contained in:
parent
cdcb5c25b7
commit
83baec368b
11 changed files with 55 additions and 29 deletions
|
@ -33,8 +33,8 @@
|
|||
INIT_LOGGER(game, Move);
|
||||
|
||||
|
||||
Move::Move()
|
||||
:m_score(0)
|
||||
Move::Move(int iPoints)
|
||||
:m_score(iPoints)
|
||||
{
|
||||
m_type = NO_MOVE;
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ class Move
|
|||
/**
|
||||
* Default constructor, corresponding to no move
|
||||
*/
|
||||
Move();
|
||||
Move(int iPoints = 0);
|
||||
|
||||
/**
|
||||
* Constructor taking a (valid) round
|
||||
|
|
|
@ -262,9 +262,9 @@ void PublicGame::toppingPlay(const wstring &iWord, const wstring &iCoord, int iE
|
|||
}
|
||||
|
||||
|
||||
void PublicGame::toppingTimeOut()
|
||||
void PublicGame::toppingTimeOut(int iElapsed)
|
||||
{
|
||||
getTypedGame<Topping>(m_game).turnTimeOut();
|
||||
getTypedGame<Topping>(m_game).turnTimeOut(iElapsed);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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<int>(tmpConf, *m_conf, "arbitration.solo-value");
|
||||
copySetting<int>(tmpConf, *m_conf, "arbitration.penalty-value");
|
||||
copySetting<int>(tmpConf, *m_conf, "arbitration.warnings-limit");
|
||||
copySetting<int>(tmpConf, *m_conf, "topping.elapsed-penalty");
|
||||
copySetting<int>(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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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());
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -254,7 +254,7 @@ void ToppingWidget::timeoutPenalty()
|
|||
.arg(move.getScore()));
|
||||
|
||||
// End the turn
|
||||
m_game->toppingTimeOut();
|
||||
m_game->toppingTimeOut(m_timerModel->getTotalDuration());
|
||||
emit gameUpdated();
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>474</width>
|
||||
<height>699</height>
|
||||
<height>737</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -495,14 +495,14 @@
|
|||
<string>_("Topping mode")</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_4">
|
||||
<item row="1" column="0">
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_11">
|
||||
<property name="text">
|
||||
<string>_("Additional penalty given when the timer expires:"</string>
|
||||
<string>_("Additional penalty given when the timer expires:")</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<item row="2" column="1">
|
||||
<widget class="QSpinBox" name="spinBoxToppingExpPenalty">
|
||||
<property name="maximum">
|
||||
<number>9999</number>
|
||||
|
@ -512,7 +512,14 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<item row="0" column="0">
|
||||
<widget class="QCheckBox" name="checkBoxToppingElapsedPenalty">
|
||||
<property name="text">
|
||||
<string>_("Give a 1 point penalty for each elapsed second")</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<spacer name="horizontalSpacer_5">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
|
|
Loading…
Reference in a new issue