Skip to content

Commit a70c591

Browse files
alweyilaripih
authored andcommitted
Add way to switch on debugging on UCI engines
Some changed to the original PR by @ilaripih Introduce debugEnabled to EngineConfiguration. Introduce formal engine option "debug" e.g. cutechess-cli -each ponder debug opt.op1=value. Introduce ChessEngine::debugEnabled. Send "debug on" in UciEngine::startGame if debugEnabled() Add support for GUI: Add m_debugCheck to EngineConfigDlg abdsupporting logic to EngineConfigurationDlg. Resolves #505
1 parent 69c3779 commit a70c591

File tree

10 files changed

+88
-7
lines changed

10 files changed

+88
-7
lines changed

docs/cutechess-cli.6

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,8 @@ Set the node count limit.
500500
Scale engine timeouts by
501501
.Ar factor .
502502
Only use this option if necessary.
503+
.It Ic debug
504+
Activate debug mode (per protocol, UCI only).
503505
.El
504506
.Sh EXAMPLES
505507
Play ten games between two Sloppy engines with a time control of 40

projects/cli/res/doc/help.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,5 +223,6 @@ Engine options:
223223
pondering is disabled.
224224
tscale=FACTOR Scale engine timeouts by FACTOR. Only use this option
225225
if necessary.
226+
debug Activate debug mode per protocol (UCI only).
226227
option.OPTION=VALUE Set custom option OPTION to value VALUE
227228

projects/cli/src/main.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ bool parseEngine(const QStringList& args, EngineData& data)
234234
{
235235
data.config.setPondering(true);
236236
}
237+
else if (name == "debug")
238+
{
239+
data.config.setDebugEnabled(true);
240+
}
237241
// Custom engine option
238242
else if (name.startsWith("option."))
239243
data.config.setOption(name.section('.', 1), val);
@@ -271,7 +275,7 @@ EngineMatch* parseMatch(const QStringList& args, QObject* parent)
271275
parser.addOption("-ratinginterval", QVariant::Int, 1, 1);
272276
parser.addOption("-outcomeinterval", QVariant::Int, 1, 1);
273277
parser.addOption("-resultformat", QVariant::String, 1, 1);
274-
parser.addOption("-debug", QVariant::Bool, 0, 0);
278+
parser.addOption("-debug", QVariant::String, 0, 1);
275279
parser.addOption("-openings", QVariant::StringList);
276280
parser.addOption("-bookmode", QVariant::String);
277281
parser.addOption("-pgnout", QVariant::StringList, 1, 3);
@@ -479,6 +483,10 @@ EngineMatch* parseMatch(const QStringList& args, QObject* parent)
479483
{
480484
QLoggingCategory::defaultCategory()->setEnabled(QtDebugMsg, true);
481485
match->setDebugMode(true);
486+
if (value == "all")
487+
eachOptions.append("debug");
488+
else if (!value.isNull())
489+
ok = false;
482490
}
483491
// Use an opening suite
484492
else if (name == "-openings")

projects/gui/src/engineconfigurationdlg.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,16 @@ EngineConfigurationDialog::EngineConfigurationDialog(
9494
[=](const QString& text)
9595
{
9696
if (text == "xboard")
97+
{
9798
ui->m_whitePovCheck->setEnabled(true);
99+
ui->m_debugCheck->setChecked(false);
100+
ui->m_debugCheck->setEnabled(false);
101+
}
98102
else
99103
{
100104
ui->m_whitePovCheck->setChecked(false);
101105
ui->m_whitePovCheck->setEnabled(false);
106+
ui->m_debugCheck->setChecked(false);
102107
}
103108
});
104109

@@ -138,6 +143,9 @@ void EngineConfigurationDialog::applyEngineInformation(
138143
if (engine.whiteEvalPov())
139144
ui->m_whitePovCheck->setCheckState(Qt::Checked);
140145

146+
if (engine.debugEnabled())
147+
ui->m_debugCheck->setCheckState(Qt::Checked);
148+
141149
const auto options = engine.options();
142150
for (const EngineOption* option : options)
143151
m_options << option->copy();
@@ -165,6 +173,7 @@ EngineConfiguration EngineConfigurationDialog::engineConfiguration()
165173
engine.setInitStrings(initStr.split('\n'));
166174

167175
engine.setWhiteEvalPov(ui->m_whitePovCheck->checkState() == Qt::Checked);
176+
engine.setDebugEnabled(ui->m_debugCheck->checkState() == Qt::Checked);
168177

169178
QList<EngineOption*> optionCopies;
170179
for (const EngineOption* option : qAsConst(m_options))

projects/gui/ui/engineconfigdlg.ui

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>480</width>
10-
<height>400</height>
9+
<width>519</width>
10+
<height>477</height>
1111
</rect>
1212
</property>
1313
<layout class="QVBoxLayout" name="verticalLayout_3">
@@ -189,6 +189,16 @@
189189
</item>
190190
</layout>
191191
</item>
192+
<item row="7" column="1">
193+
<widget class="QCheckBox" name="m_debugCheck">
194+
<property name="toolTip">
195+
<string>The engine is put into debug mode, if the engine supports it</string>
196+
</property>
197+
<property name="text">
198+
<string>Debug</string>
199+
</property>
200+
</widget>
201+
</item>
192202
</layout>
193203
</widget>
194204
<widget class="QWidget" name="tab_2">

projects/lib/src/chessengine.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ ChessEngine::ChessEngine(QObject* parent)
7777
m_whiteEvalPov(false),
7878
m_pondering(false),
7979
m_timeoutScale(1.0),
80+
m_debugEnabled(false),
8081
m_pingTimer(new QTimer(this)),
8182
m_quitTimer(new QTimer(this)),
8283
m_idleTimer(new QTimer(this)),
@@ -143,6 +144,8 @@ void ChessEngine::applyConfiguration(const EngineConfiguration& configuration)
143144
m_pondering = configuration.pondering();
144145
m_timeoutScale = configuration.timeoutScale();
145146
m_restartMode = configuration.restartMode();
147+
m_debugEnabled = configuration.debugEnabled();
148+
146149
setClaimsValidated(configuration.areClaimsValidated());
147150

148151
// Read protocol timeouts from QSettings.
@@ -295,6 +298,11 @@ bool ChessEngine::pondering() const
295298
return m_pondering;
296299
}
297300

301+
bool ChessEngine::debugEnabled() const
302+
{
303+
return m_debugEnabled;
304+
}
305+
298306
void ChessEngine::endGame(const Chess::Result& result)
299307
{
300308
ChessPlayer::endGame(result);

projects/lib/src/chessengine.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,16 @@ class LIB_EXPORT ChessEngine : public ChessPlayer
232232
* the engine does not support pondering.
233233
*/
234234
bool pondering() const;
235+
236+
/*!
237+
* Returns true if debugging is enabled for the engine;
238+
* otherwise returns false.
239+
*
240+
* \note Even if debugging is enabled, it's still possible that
241+
* the engine does not support debugging.
242+
*/
243+
bool debugEnabled() const;
244+
235245
/*!
236246
* Gives id number of the engine
237247
*/
@@ -295,6 +305,7 @@ class LIB_EXPORT ChessEngine : public ChessPlayer
295305
bool m_whiteEvalPov;
296306
bool m_pondering;
297307
double m_timeoutScale;
308+
bool m_debugEnabled;
298309
QTimer* m_pingTimer;
299310
QTimer* m_quitTimer;
300311
QTimer* m_idleTimer;

projects/lib/src/engineconfiguration.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ EngineConfiguration::EngineConfiguration()
2828
m_pondering(false),
2929
m_validateClaims(true),
3030
m_timeoutScale(1.0),
31-
m_restartMode(RestartAuto)
31+
m_restartMode(RestartAuto),
32+
m_debugEnabled(false)
3233
{
3334
}
3435

@@ -43,7 +44,8 @@ EngineConfiguration::EngineConfiguration(const QString& name,
4344
m_pondering(false),
4445
m_validateClaims(true),
4546
m_timeoutScale(1.0),
46-
m_restartMode(RestartAuto)
47+
m_restartMode(RestartAuto),
48+
m_debugEnabled(false)
4749
{
4850
}
4951

@@ -53,7 +55,8 @@ EngineConfiguration::EngineConfiguration(const QVariant& variant)
5355
m_pondering(false),
5456
m_validateClaims(true),
5557
m_timeoutScale(1.0),
56-
m_restartMode(RestartAuto)
58+
m_restartMode(RestartAuto),
59+
m_debugEnabled(false)
5760
{
5861
const QVariantMap map = variant.toMap();
5962

@@ -90,6 +93,8 @@ EngineConfiguration::EngineConfiguration(const QVariant& variant)
9093

9194
if (map.contains("validateClaims"))
9295
setClaimsValidated(map["validateClaims"].toBool());
96+
if (map.contains("debug"))
97+
setDebugEnabled(map["debug"].toBool());
9398

9499
if (map.contains("variants"))
95100
setSupportedVariants(map["variants"].toStringList());
@@ -120,7 +125,8 @@ EngineConfiguration::EngineConfiguration(const EngineConfiguration& other)
120125
m_pondering(other.m_pondering),
121126
m_validateClaims(other.m_validateClaims),
122127
m_timeoutScale(other.m_timeoutScale),
123-
m_restartMode(other.m_restartMode)
128+
m_restartMode(other.m_restartMode),
129+
m_debugEnabled(other.debugEnabled())
124130
{
125131
const auto options = other.options();
126132
for (const EngineOption* option : options)
@@ -146,6 +152,7 @@ EngineConfiguration& EngineConfiguration::operator=(EngineConfiguration&& other)
146152
m_validateClaims = other.m_validateClaims;
147153
m_timeoutScale = other.m_timeoutScale;
148154
m_restartMode = other.m_restartMode;
155+
m_debugEnabled =other.m_debugEnabled;
149156
m_options = other.m_options;
150157

151158
// other's destructor will cause a mess if its m_options isn't cleared
@@ -183,6 +190,8 @@ QVariant EngineConfiguration::toVariant() const
183190

184191
if (!m_validateClaims)
185192
map.insert("validateClaims", false);
193+
if (m_debugEnabled)
194+
map.insert("debug", true);
186195

187196
if (m_variants.count("standard") != m_variants.count())
188197
map.insert("variants", m_variants);
@@ -384,6 +393,16 @@ void EngineConfiguration::setTimeoutScale(double value)
384393
m_timeoutScale = qBound(timeoutScaleMin, value, timeoutScaleMax);
385394
}
386395

396+
bool EngineConfiguration::debugEnabled() const
397+
{
398+
return m_debugEnabled;
399+
}
400+
401+
void EngineConfiguration::setDebugEnabled(bool enabled)
402+
{
403+
m_debugEnabled = enabled;
404+
}
405+
387406
EngineConfiguration& EngineConfiguration::operator=(const EngineConfiguration& other)
388407
{
389408
if (this != &other)
@@ -401,6 +420,7 @@ EngineConfiguration& EngineConfiguration::operator=(const EngineConfiguration& o
401420
m_pondering = other.m_pondering;
402421
m_validateClaims = other.m_validateClaims;
403422
m_restartMode = other.m_restartMode;
423+
m_debugEnabled = other.m_debugEnabled;
404424

405425
qDeleteAll(m_options);
406426
m_options.clear();

projects/lib/src/engineconfiguration.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,14 @@ class LIB_EXPORT EngineConfiguration
227227
*/
228228
void setTimeoutScale(double value);
229229

230+
/*!
231+
* Returns true if debug mode is enabled for the engine,
232+
* else false.
233+
*/
234+
bool debugEnabled() const;
235+
/*! Sets the debug mode to \a enabled */
236+
void setDebugEnabled(bool enabled);
237+
230238
/*!
231239
* Assigns \a other to this engine configuration and returns
232240
* a reference to this object.
@@ -248,6 +256,7 @@ class LIB_EXPORT EngineConfiguration
248256
bool m_validateClaims;
249257
double m_timeoutScale;
250258
RestartMode m_restartMode;
259+
bool m_debugEnabled;
251260
};
252261

253262
#endif // ENGINE_CONFIGURATION_H

projects/lib/src/uciengine.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ void UciEngine::startGame()
148148
m_startFen = board()->fenString(Chess::Board::XFen);
149149
setVariant(board()->variant());
150150

151+
if (debugEnabled())
152+
write("debug on");
153+
151154
write("ucinewgame");
152155

153156
if (m_canPonder)

0 commit comments

Comments
 (0)