Skip to content

Commit bb00bd9

Browse files
windfishballadAloril
authored andcommitted
Add support for new draw rule
1 parent e0e540e commit bb00bd9

File tree

9 files changed

+212
-21
lines changed

9 files changed

+212
-21
lines changed

.cproject

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
3+
<storageModule moduleId="org.eclipse.cdt.core.settings">
4+
<cconfiguration id="0.221125070">
5+
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="0.221125070" moduleId="org.eclipse.cdt.core.settings" name="Default">
6+
<externalSettings/>
7+
<extensions>
8+
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
9+
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
10+
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
11+
<extension id="org.eclipse.cdt.core.VCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
12+
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
13+
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
14+
</extensions>
15+
</storageModule>
16+
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
17+
<configuration buildProperties="" description="" id="0.221125070" name="Default" optionalBuildProperties="" parent="org.eclipse.cdt.build.core.prefbase.cfg">
18+
<folderInfo id="0.221125070." name="/" resourcePath="">
19+
<toolChain id="org.eclipse.cdt.build.core.prefbase.toolchain.1975824261" name="No ToolChain" resourceTypeBasedDiscovery="false" superClass="org.eclipse.cdt.build.core.prefbase.toolchain">
20+
<targetPlatform id="org.eclipse.cdt.build.core.prefbase.toolchain.1975824261.1935259350" name=""/>
21+
<builder id="org.eclipse.cdt.build.core.settings.default.builder.2024670838" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="128" superClass="org.eclipse.cdt.build.core.settings.default.builder"/>
22+
<tool id="org.eclipse.cdt.build.core.settings.holder.libs.784730800" name="holder for library settings" superClass="org.eclipse.cdt.build.core.settings.holder.libs"/>
23+
<tool id="org.eclipse.cdt.build.core.settings.holder.2133460289" name="Assembly" superClass="org.eclipse.cdt.build.core.settings.holder">
24+
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.838142485" languageId="org.eclipse.cdt.core.assembly" languageName="Assembly" sourceContentType="org.eclipse.cdt.core.asmSource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
25+
</tool>
26+
<tool id="org.eclipse.cdt.build.core.settings.holder.1400753683" name="GNU C++" superClass="org.eclipse.cdt.build.core.settings.holder">
27+
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1792942416" languageId="org.eclipse.cdt.core.g++" languageName="GNU C++" sourceContentType="org.eclipse.cdt.core.cxxSource,org.eclipse.cdt.core.cxxHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
28+
</tool>
29+
<tool id="org.eclipse.cdt.build.core.settings.holder.1665038016" name="GNU C" superClass="org.eclipse.cdt.build.core.settings.holder">
30+
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.344956199" languageId="org.eclipse.cdt.core.gcc" languageName="GNU C" sourceContentType="org.eclipse.cdt.core.cSource,org.eclipse.cdt.core.cHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
31+
</tool>
32+
</toolChain>
33+
</folderInfo>
34+
</configuration>
35+
</storageModule>
36+
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
37+
</cconfiguration>
38+
</storageModule>
39+
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
40+
<project id="tceccutechess.null.1017364817" name="tceccutechess"/>
41+
</storageModule>
42+
<storageModule moduleId="scannerConfiguration">
43+
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
44+
<scannerConfigBuildInfo instanceId="0.221125070">
45+
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
46+
</scannerConfigBuildInfo>
47+
</storageModule>
48+
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
49+
<storageModule moduleId="refreshScope" versionNumber="2">
50+
<configuration configurationName="Default">
51+
<resource resourceType="PROJECT" workspacePath="/tceccutechess"/>
52+
</configuration>
53+
</storageModule>
54+
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
55+
</cproject>

.project

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>tceccutechess</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
10+
<triggers>clean,full,incremental,</triggers>
11+
<arguments>
12+
</arguments>
13+
</buildCommand>
14+
<buildCommand>
15+
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
16+
<triggers>full,incremental,</triggers>
17+
<arguments>
18+
</arguments>
19+
</buildCommand>
20+
</buildSpec>
21+
<natures>
22+
<nature>org.eclipse.cdt.core.cnature</nature>
23+
<nature>org.eclipse.cdt.core.ccnature</nature>
24+
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
25+
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
26+
</natures>
27+
</projectDescription>

.qmake.stash

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
QMAKE_CXX.QT_COMPILER_STDCXX = 201402L
2+
QMAKE_CXX.QMAKE_GCC_MAJOR_VERSION = 9
3+
QMAKE_CXX.QMAKE_GCC_MINOR_VERSION = 4
4+
QMAKE_CXX.QMAKE_GCC_PATCH_VERSION = 0
5+
QMAKE_CXX.COMPILER_MACROS = \
6+
QT_COMPILER_STDCXX \
7+
QMAKE_GCC_MAJOR_VERSION \
8+
QMAKE_GCC_MINOR_VERSION \
9+
QMAKE_GCC_PATCH_VERSION
10+
QMAKE_CXX.INCDIRS = \
11+
/home/david/TensorRT-8.2.3.0/lib \
12+
/usr/local/cuda-11.6/targets/x86_64-linux/include \
13+
/usr/local/cuda-11.6/lib64 \
14+
. \
15+
/usr/include/c++/9 \
16+
/usr/include/x86_64-linux-gnu/c++/9 \
17+
/usr/include/c++/9/backward \
18+
/usr/lib/gcc/x86_64-linux-gnu/9/include \
19+
/usr/local/include \
20+
/usr/include/x86_64-linux-gnu \
21+
/usr/include
22+
QMAKE_CXX.LIBDIRS = \
23+
/usr/lib/gcc/x86_64-linux-gnu/9 \
24+
/usr/lib/x86_64-linux-gnu \
25+
/usr/lib \
26+
/lib/x86_64-linux-gnu \
27+
/lib \
28+
.

projects/cli/src/main.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -571,12 +571,18 @@ EngineMatch* parseMatch(const QStringList& args, CuteChessCoreApplication& app)
571571
QVariantMap dMap = tMap["drawAdjudication"].toMap();
572572
if (dMap.contains("movenumber") &&
573573
dMap.contains("movecount") &&
574-
dMap.contains("score"))
574+
dMap.contains("score") &&
575+
dMap.contains("maxPieces") &&
576+
dMap.contains("maxPawns") &&
577+
dMap.contains("reset"))
575578
{
576579
adjudicator.setDrawThreshold(
577580
dMap["movenumber"].toInt(),
578581
dMap["movecount"].toInt(),
579-
dMap["score"].toInt());
582+
dMap["score"].toInt(),
583+
dMap["maxPieces"].toInt(),
584+
dMap["maxPawns"].toInt(),
585+
dMap["reset"].toInt());
580586
}
581587
}
582588
if (tMap.contains("resignAdjudication")) {
@@ -725,21 +731,30 @@ EngineMatch* parseMatch(const QStringList& args, CuteChessCoreApplication& app)
725731
else if (name == "-draw")
726732
{
727733
QMap<QString, QString> params =
728-
option.toMap("movenumber|movecount|score");
734+
option.toMap("movenumber|movecount|score|maxpieces=32|maxpawns=16|reset=true");
729735
bool numOk = false;
730736
bool countOk = false;
731737
bool scoreOk = false;
738+
bool maxPiecesOk = false;
739+
bool maxPawnsOk = false;
732740
int moveNumber = params["movenumber"].toInt(&numOk);
733741
int moveCount = params["movecount"].toInt(&countOk);
734742
int score = params["score"].toInt(&scoreOk);
743+
int maxPieces = params["maxpieces"].toInt(&maxPiecesOk);
744+
int maxPawns = params["maxpawns"].toInt(&maxPawnsOk);
745+
bool reset = params["reset"] == "true";
746+
747+
ok = (numOk && countOk && scoreOk && maxPiecesOk && maxPawnsOk);
735748

736-
ok = (numOk && countOk && scoreOk);
737749
if (ok) {
738-
adjudicator.setDrawThreshold(moveNumber, moveCount, score);
750+
adjudicator.setDrawThreshold(moveNumber, moveCount, score, maxPieces, maxPawns, reset);
739751
QVariantMap dMap;
740752
dMap.insert("movenumber", moveNumber);
741753
dMap.insert("movecount", moveCount);
742754
dMap.insert("score", score);
755+
dMap.insert("maxPieces", maxPieces);
756+
dMap.insert("maxPawns", maxPawns);
757+
dMap.insert("reset", reset);
743758
tMap.insert("drawAdjudication", dMap);
744759
}
745760
}

projects/lib/src/board/board.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,32 @@ QStringList Board::pieceList(Side side) const
474474
return list;
475475
}
476476

477+
int Board::pieceCount() const
478+
{
479+
int count=0;
480+
for (int file = 0; file < height(); file++)
481+
for (int rank = 0; rank < width(); rank++)
482+
{
483+
Square sq = Chess::Square(file, rank);
484+
const Piece piece = pieceAt(sq);
485+
if (piece.type()>1) count++;
486+
}
487+
return count;
488+
}
489+
490+
int Board::pawnCount() const
491+
{
492+
int count=0;
493+
for (int file = 0; file < height(); file++)
494+
for (int rank = 0; rank < width(); rank++)
495+
{
496+
Square sq = Chess::Square(file, rank);
497+
const Piece piece = pieceAt(sq);
498+
if (piece.type()==1) count++;
499+
}
500+
return count;
501+
}
502+
477503
QString Board::fenString(FenNotation notation) const
478504
{
479505
QString fen;

projects/lib/src/board/board.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,15 @@ class LIB_EXPORT Board
301301
* The default implementation always returns a null result.
302302
*/
303303
virtual Result tablebaseResult(unsigned int* dtm = nullptr) const;
304+
/*!
305+
* Counts the pieces of type 1 (pawns in Western Board)
306+
*/
307+
int pawnCount() const;
308+
/*!
309+
* Counts the pieces of type >= 2 (non-pawn pieces in Western Board)
310+
*/
311+
int pieceCount() const;
312+
304313

305314
protected:
306315
/*!
@@ -516,6 +525,7 @@ class LIB_EXPORT Board
516525
/*! Removes a piece of type \a piece from the reserve. */
517526
void removeFromReserve(const Piece& piece);
518527

528+
519529
private:
520530
struct PieceData
521531
{

projects/lib/src/chessgame.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ void ChessGame::onMoveMade(const Chess::Move& move)
495495
m_result = m_board->result();
496496
if (m_result.isNone())
497497
{
498-
if (m_board->reversibleMoveCount() == 0)
498+
if (m_adjudicator.resets() && m_board->reversibleMoveCount() == 0)
499499
m_adjudicator.resetDrawMoveCount();
500500

501501
m_adjudicator.addEval(m_board, sender->evaluation());

projects/lib/src/gameadjudicator.cpp

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,18 @@ GameAdjudicator::GameAdjudicator()
2929
m_resignScore(0),
3030
m_maxGameLength(0),
3131
m_tbEnabled(false),
32-
m_tcecAdjudication(false)
32+
m_tcecAdjudication(false),
33+
m_maxPawns(0),
34+
m_maxPieces(0),
35+
m_reset(true)
3336
{
3437
m_resignScoreCount[0] = 0;
3538
m_resignScoreCount[1] = 0;
3639
m_resignWinnerScoreCount[0] = 0;
3740
m_resignWinnerScoreCount[1] = 0;
3841
}
3942

40-
void GameAdjudicator::setDrawThreshold(int moveNumber, int moveCount, int score)
43+
void GameAdjudicator::setDrawThreshold(int moveNumber, int moveCount, int score, int maxPieces /*=0*/, int maxPawns /*=0*/, bool reset /*=true*/)
4144
{
4245
Q_ASSERT(moveNumber >= 0);
4346
Q_ASSERT(moveCount >= 0);
@@ -46,6 +49,11 @@ void GameAdjudicator::setDrawThreshold(int moveNumber, int moveCount, int score)
4649
m_drawMoveCount = moveCount;
4750
m_drawScore = score;
4851
m_drawScoreCount = 0;
52+
m_maxPieces=maxPieces;
53+
m_maxPawns=maxPawns;
54+
m_reset=reset;
55+
56+
4957
}
5058

5159
void GameAdjudicator::setResignThreshold(int moveCount, int score)
@@ -72,6 +80,7 @@ void GameAdjudicator::setTablebaseAdjudication(bool enable, bool drawOnly)
7280
m_tbDrawOnly = drawOnly;
7381
}
7482

83+
7584
void GameAdjudicator::setTcecAdjudication(bool enable)
7685
{
7786
m_tcecAdjudication = enable;
@@ -117,21 +126,28 @@ void GameAdjudicator::addEval(const Chess::Board* board, const MoveEvaluation& e
117126
// Draw adjudication
118127
if (m_drawMoveNum > 0)
119128
{
120-
if (m_tcecAdjudication && board->reversibleMoveCount() == 0)
129+
if (m_tcecAdjudication && m_reset && board->reversibleMoveCount() == 0)
121130
{} // m_drawScoreCount == 0;
122131
else
123132
{
124-
if (qAbs(eval.score()) <= m_drawScore)
125-
m_drawScoreCount++;
133+
if ((m_maxPawns==0 || board->pawnCount()<=m_maxPawns) && (m_maxPieces==0 || board->pieceCount()<=m_maxPieces))
134+
{
135+
if (qAbs(eval.score()) <= m_drawScore)
136+
m_drawScoreCount++;
137+
else
138+
m_drawScoreCount = 0;
139+
140+
if (board->plyCount() / 2 >= m_drawMoveNum
141+
&& m_drawScoreCount >= m_drawMoveCount * 2)
142+
{
143+
m_result = Chess::Result(Chess::Result::Adjudication,
144+
Chess::Side::NoSide, "TCEC draw rule");
145+
return;
146+
}
147+
}
126148
else
127-
m_drawScoreCount = 0;
128-
129-
if (board->plyCount() / 2 >= m_drawMoveNum
130-
&& m_drawScoreCount >= m_drawMoveCount * 2)
131149
{
132-
m_result = Chess::Result(Chess::Result::Adjudication,
133-
Chess::Side::NoSide, "TCEC draw rule");
134-
return;
150+
m_drawScoreCount = 0;
135151
}
136152
}
137153
}
@@ -196,6 +212,11 @@ void GameAdjudicator::resetDrawMoveCount()
196212
m_drawScoreCount = 0;
197213
}
198214

215+
bool GameAdjudicator::resets()const
216+
{
217+
return m_reset;
218+
}
219+
199220
Chess::Result GameAdjudicator::result() const
200221
{
201222
return m_result;

projects/lib/src/gameadjudicator.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,17 @@ class LIB_EXPORT GameAdjudicator
4747
* least \a moveCount consecutive moves, and at least
4848
* \a moveNumber full moves have been played.
4949
*/
50-
void setDrawThreshold(int moveNumber, int moveCount, int score);
50+
void setDrawThreshold(int moveNumber, int moveCount, int score, int maxPieces=0, int maxPawns=0, bool reset=true);
5151
/*!
5252
* Sets the resign adjudication threshold for each game.
5353
*
5454
* A game will be adjudicated as a loss for the player that
5555
* made the last move if it reports a score that's at least
5656
* \a score centipawns below zero for at least \a moveCount
57-
* consecutive moves.
57+
* consecutive moves. If \a maxPieces>0, number of non-pawn pieces also needs to be no greater than \a maxPieces
58+
* for the consecutive moves. Ditto with \a maxPawns for pawns. If \a reset is true, any reversible moves resets the count
59+
* of consecutive moves to 0.
60+
*
5861
*/
5962
void setResignThreshold(int moveCount, int score);
6063
/*!
@@ -79,7 +82,6 @@ class LIB_EXPORT GameAdjudicator
7982
* evaluations to be below the setResignThreshold score.
8083
*/
8184
void setTcecAdjudication(bool enable);
82-
8385
/*!
8486
* Adds a new move evaluation to the adjudicator.
8587
*
@@ -107,6 +109,10 @@ class LIB_EXPORT GameAdjudicator
107109
* Returns the number of plies left until resign rule adjudication.
108110
*/
109111
int resignClock(const Chess::Board* board, const MoveEvaluation& eval) const;
112+
/*!
113+
* Returns true if the draw rules count resets on irreversible moves
114+
*/
115+
bool resets() const;
110116

111117
private:
112118
int m_drawMoveNum;
@@ -122,6 +128,9 @@ class LIB_EXPORT GameAdjudicator
122128
Chess::Result m_result;
123129
int m_resignWinnerScoreCount[2];
124130
bool m_tcecAdjudication;
131+
int m_maxPawns;
132+
int m_maxPieces;
133+
bool m_reset;
125134
};
126135

127136
#endif // GAMEADJUDICATOR_H

0 commit comments

Comments
 (0)