Skip to content

Commit 069a9f4

Browse files
skiminkiAloril
authored andcommitted
Cuteseal support for cutechess
1 parent 8eb50a7 commit 069a9f4

File tree

12 files changed

+136
-18
lines changed

12 files changed

+136
-18
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,6 @@ qtc-gdbmacros/
8181

8282
# Installation packages
8383
dist/linux/package
84+
85+
# Cuteseal remote runner
86+
cuteseal-remote-runner/cuteseal-remote-runner

projects/cli/src/main.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,12 @@ bool parseEngine(const QStringList& args, EngineData& data, QVariantMap stMap, Q
342342
{
343343
data.config.setPondering(true);
344344
}
345+
else if (name == "cuteseal")
346+
{
347+
bool useCuteseal = (val.toUpper() == "TRUE");
348+
qWarning() << "CUTESEAL " << useCuteseal;
349+
data.config.setCuteseal(useCuteseal);
350+
}
345351
// Custom engine option
346352
else if (name.startsWith("option."))
347353
data.config.setOption(name.section('.', 1), val);

projects/lib/src/chessengine.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ ChessEngine::ChessEngine(QObject* parent)
8181
m_idleTimer(new QTimer(this)),
8282
m_protocolStartTimer(new QTimer(this)),
8383
m_ioDevice(nullptr),
84-
m_restartMode(EngineConfiguration::RestartAuto)
84+
m_restartMode(EngineConfiguration::RestartAuto),
85+
m_cuteseal(false)
8586
{
8687
m_pingTimer->setSingleShot(true);
8788
m_pingTimer->setInterval(120000);
@@ -149,6 +150,8 @@ void ChessEngine::applyConfiguration(const EngineConfiguration& configuration)
149150

150151
if (configuration.rating())
151152
setRating(configuration.rating());
153+
154+
m_cuteseal = configuration.isCuteseal();
152155
}
153156

154157
void ChessEngine::addOption(EngineOption* option)
@@ -298,6 +301,11 @@ bool ChessEngine::pondering() const
298301
return m_pondering;
299302
}
300303

304+
bool ChessEngine::isCuteseal() const
305+
{
306+
return m_cuteseal;
307+
}
308+
301309
void ChessEngine::endGame(const Chess::Result& result)
302310
{
303311
ChessPlayer::endGame(result);

projects/lib/src/chessengine.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ class LIB_EXPORT ChessEngine : public ChessPlayer
230230
*/
231231
bool pondering() const;
232232

233+
bool isCuteseal() const;
234+
233235
protected slots:
234236
// Inherited from ChessPlayer
235237
virtual void onTimeout();
@@ -292,6 +294,7 @@ class LIB_EXPORT ChessEngine : public ChessPlayer
292294
QMap<QString, QVariant> m_optionBuffer;
293295
EngineConfiguration::RestartMode m_restartMode;
294296
QString m_configurationString;
297+
bool m_cuteseal;
295298
};
296299

297300
#endif // CHESSENGINE_H

projects/lib/src/chessplayer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ void ChessPlayer::startClock()
130130

131131
if (!m_timeControl.isInfinite())
132132
{
133-
int t = m_timeControl.timeLeft() + m_timeControl.expiryMargin();
133+
int t = m_timeControl.timeLeft() + m_timeControl.expiryMargin() + getMaxNetLagMs();
134134
m_timer->start(qMax(t, 0) + 200);
135135
}
136136
}
@@ -275,12 +275,12 @@ void ChessPlayer::forfeit(Chess::Result::Type type, const QString& description)
275275
claimResult(Chess::Result(type, m_side.opposite(), description));
276276
}
277277

278-
void ChessPlayer::emitMove(const Chess::Move& move)
278+
void ChessPlayer::emitMove(const Chess::Move& move, int64_t overrideMoveTimeMs)
279279
{
280280
if (m_state == Thinking)
281281
setState(Observing);
282282

283-
m_timeControl.update();
283+
m_timeControl.update(true, overrideMoveTimeMs);
284284
m_eval.setTime(m_timeControl.lastMoveTime());
285285

286286
m_timer->stop();

projects/lib/src/chessplayer.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,11 @@ class LIB_EXPORT ChessPlayer : public QObject
280280
/*!
281281
* Emits the player's move, and a timeout signal if the
282282
* move came too late.
283+
*
284+
* The move time is overridden by actual move times when
285+
* cuteseal is enabled.
283286
*/
284-
void emitMove(const Chess::Move& move);
287+
void emitMove(const Chess::Move& move, int64_t overrideMoveTimeMs = -1);
285288

286289
/*! Returns the opposing player. */
287290
const ChessPlayer* opponent() const;
@@ -301,6 +304,14 @@ class LIB_EXPORT ChessPlayer : public QObject
301304
*/
302305
MoveEvaluation m_eval;
303306

307+
/*!
308+
* Maximum allowed net lag (millisecs). This adds to the
309+
* timer-based timeout. By default, we use local engines and we
310+
* don't allow any net-based lag. With cuteseal netlag
311+
* compensator, this should be set to something like 30 secs, as
312+
* the cuteseal-remote-runner will remotely flag the timeouts.
313+
*/
314+
virtual int getMaxNetLagMs() const { return 0; }
304315
private:
305316
void startClock();
306317

projects/lib/src/engineconfiguration.cpp

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ EngineConfiguration::EngineConfiguration()
3030
m_restartMode(RestartAuto),
3131
m_rating(0),
3232
m_restart_score(0),
33-
m_strikes(0)
33+
m_strikes(0),
34+
m_cuteseal(false)
3435
{
3536
}
3637

@@ -47,7 +48,8 @@ EngineConfiguration::EngineConfiguration(const QString& name,
4748
m_restartMode(RestartAuto),
4849
m_rating(0),
4950
m_restart_score(0),
50-
m_strikes(0)
51+
m_strikes(0),
52+
m_cuteseal(false)
5153
{
5254
}
5355

@@ -59,7 +61,8 @@ EngineConfiguration::EngineConfiguration(const QVariant& variant)
5961
m_restartMode(RestartAuto),
6062
m_rating(0),
6163
m_restart_score(0),
62-
m_strikes(0)
64+
m_strikes(0),
65+
m_cuteseal(false)
6366
{
6467
const QVariantMap map = variant.toMap();
6568

@@ -127,7 +130,8 @@ EngineConfiguration::EngineConfiguration(const EngineConfiguration& other)
127130
m_restartMode(other.m_restartMode),
128131
m_rating(other.m_rating),
129132
m_restart_score(other.m_restart_score),
130-
m_strikes(other.m_strikes)
133+
m_strikes(other.m_strikes),
134+
m_cuteseal(other.m_cuteseal)
131135
{
132136
const auto options = other.options();
133137
for (const EngineOption* option : options)
@@ -157,6 +161,7 @@ EngineConfiguration& EngineConfiguration::operator=(EngineConfiguration&& other)
157161
m_rating = other.m_rating;
158162
m_strikes = other.m_strikes;
159163
m_restart_score = other.m_restart_score;
164+
m_cuteseal = other.m_cuteseal;
160165
// other's destructor will cause a mess if its m_options isn't cleared
161166
other.m_options.clear();
162167
return *this;
@@ -210,6 +215,9 @@ QVariant EngineConfiguration::toVariant() const
210215
if (m_strikes > 0)
211216
map.insert("strikes", m_strikes);
212217

218+
if (m_cuteseal)
219+
map.insert("cuteseal", true);
220+
213221
return map;
214222
}
215223

@@ -418,6 +426,16 @@ void EngineConfiguration::setClaimsValidated(bool validate)
418426
m_validateClaims = validate;
419427
}
420428

429+
void EngineConfiguration::setCuteseal(bool cuteseal)
430+
{
431+
m_cuteseal = cuteseal;
432+
}
433+
434+
bool EngineConfiguration::isCuteseal() const
435+
{
436+
return m_cuteseal;
437+
}
438+
421439
EngineConfiguration& EngineConfiguration::operator=(const EngineConfiguration& other)
422440
{
423441
if (this != &other)
@@ -437,6 +455,7 @@ EngineConfiguration& EngineConfiguration::operator=(const EngineConfiguration& o
437455
m_rating = other.m_rating;
438456
m_strikes = other.m_strikes;
439457
m_restart_score = other.m_restart_score;
458+
m_cuteseal = other.m_cuteseal;
440459

441460
qDeleteAll(m_options);
442461
m_options.clear();

projects/lib/src/engineconfiguration.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ class LIB_EXPORT EngineConfiguration
232232
void setClaimsValidated(bool validate);
233233
void setResumeScore(const int score);
234234

235+
void setCuteseal(bool cuteseal);
236+
bool isCuteseal() const;
237+
235238
/*!
236239
* Assigns \a other to this engine configuration and returns
237240
* a reference to this object.
@@ -258,6 +261,7 @@ class LIB_EXPORT EngineConfiguration
258261
int m_rating;
259262
int m_strikes;
260263
int m_restart_score;
264+
bool m_cuteseal;
261265
};
262266

263267
#endif // ENGINE_CONFIGURATION_H

projects/lib/src/timecontrol.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,13 +322,15 @@ void TimeControl::startTimer()
322322
m_time.start();
323323
}
324324

325-
void TimeControl::update(bool applyIncrement)
325+
void TimeControl::update(bool applyIncrement, int64_t overrideElapsedMs)
326326
{
327327
/*
328328
* This will overflow after roughly 49 days however it's unlikely
329329
* we'll ever hit that limit.
330330
*/
331-
if (m_time.isValid())
331+
if (overrideElapsedMs >= 0)
332+
m_lastMoveTime = overrideElapsedMs;
333+
else if (m_time.isValid())
332334
m_lastMoveTime = (int)m_time.elapsed();
333335
else
334336
m_lastMoveTime = 0;

projects/lib/src/timecontrol.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ class LIB_EXPORT TimeControl
181181
* Set this value to false if no increment is necessary for
182182
* the current move, e.g. for a book move.
183183
*/
184-
void update(bool applyIncrement = true);
184+
void update(bool applyIncrement = true, int64_t overrideElapsedMs = -1);
185185

186186
/*! Returns the last elapsed move time. */
187187
int lastMoveTime() const;

0 commit comments

Comments
 (0)