Skip to content

Commit c4533e0

Browse files
committed
Retire redundant endgames
The case of two lone kings on the board is already considered by the "No pawns" scaling factor rules in material.cpp as is KBK and KNK. Moreover we had a small leak in endgames map because for KK endgame it happens white and black material keys are the same (both equal to zero), so when adding the black endgame in Endgames::add() we were overwriting the already exsisting white one, leading to a memory leak found by Valgrind. So remove the endgames althogheter and rely on scaling to correctly set the endgames value to a draw. No functional change.
1 parent f39cf1b commit c4533e0

File tree

3 files changed

+2
-10
lines changed

3 files changed

+2
-10
lines changed

src/endgame.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,7 @@ namespace {
8989

9090
Endgames::Endgames() {
9191

92-
add<KK>("KK");
9392
add<KPK>("KPK");
94-
add<KBK>("KBK");
95-
add<KNK>("KNK");
9693
add<KNNK>("KNNK");
9794
add<KBNK>("KBNK");
9895
add<KRKP>("KRKP");
@@ -411,9 +408,6 @@ Value Endgame<KBBKN>::operator()(const Position& pos) const {
411408

412409

413410
/// Some cases of trivial draws
414-
template<> Value Endgame<KK>::operator()(const Position&) const { return VALUE_DRAW; }
415-
template<> Value Endgame<KBK>::operator()(const Position&) const { return VALUE_DRAW; }
416-
template<> Value Endgame<KNK>::operator()(const Position&) const { return VALUE_DRAW; }
417411
template<> Value Endgame<KNNK>::operator()(const Position&) const { return VALUE_DRAW; }
418412
template<> Value Endgame<KmmKm>::operator()(const Position&) const { return VALUE_DRAW; }
419413

src/endgame.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ enum EndgameType {
3333

3434
// Evaluation functions
3535

36-
KK, // K vs K
37-
KBK, // KB vs K
38-
KNK, // KN vs K
3936
KNNK, // KNN vs K
4037
KXK, // Generic "mate lone king" eval
4138
KBNK, // KBN vs K

src/material.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ Entry* probe(const Position& pos, Table& entries, Endgames& endgames) {
240240
}
241241
}
242242

243-
// No pawns makes it difficult to win, even with a material advantage
243+
// No pawns makes it difficult to win, even with a material advantage. This
244+
// catches some trivial draws like KK, KBK and KNK
244245
if (!pos.count<PAWN>(WHITE) && npm_w - npm_b <= BishopValueMg)
245246
{
246247
e->factor[WHITE] = (uint8_t)

0 commit comments

Comments
 (0)