Skip to content

Commit 490f67a

Browse files
committed
Move draw by material check
It is more natural to test this case among others material distributions. No functional change.
1 parent 0515ad0 commit 490f67a

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

src/endgame.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ enum EndgameType {
4343
KQKP, // KQ vs KP
4444
KQKR, // KQ vs KR
4545
KBBKN, // KBB vs KN
46-
KmmKm, // K and two minors vs K and one or two minors
46+
KmmKm, // K and one or two minors vs K and zero or one minor
4747

4848

4949
// Scaling functions

src/material.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,18 @@ Entry* probe(const Position& pos, Table& entries, Endgames& endgames) {
173173
return e;
174174
}
175175

176+
// Draw by insufficient material (trivial draws like KK, KBK and KNK)
177+
if ( !pos.pieces(PAWN)
178+
&& pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK) <= BishopValueMg)
179+
{
180+
e->evaluationFunction = &EvaluateKmmKm[pos.side_to_move()];
181+
return e;
182+
}
183+
184+
// Minor piece endgame with at least one minor piece per side and
185+
// no pawns. Note that the case KmmK is already handled by KXK.
176186
if (!pos.pieces(PAWN) && !pos.pieces(ROOK) && !pos.pieces(QUEEN))
177187
{
178-
// Minor piece endgame with at least one minor piece per side and
179-
// no pawns. Note that the case KmmK is already handled by KXK.
180188
assert((pos.pieces(WHITE, KNIGHT) | pos.pieces(WHITE, BISHOP)));
181189
assert((pos.pieces(BLACK, KNIGHT) | pos.pieces(BLACK, BISHOP)));
182190

@@ -240,8 +248,7 @@ Entry* probe(const Position& pos, Table& entries, Endgames& endgames) {
240248
}
241249
}
242250

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

src/position.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,6 +1223,7 @@ Key Position::compute_material_key() const {
12231223
/// game and the endgame. These functions are used to initialize the incremental
12241224
/// scores when a new position is set up, and to verify that the scores are correctly
12251225
/// updated by do_move and undo_move when the program is running in debug mode.
1226+
12261227
Score Position::compute_psq_score() const {
12271228

12281229
Score score = SCORE_ZERO;
@@ -1254,15 +1255,11 @@ Value Position::compute_non_pawn_material(Color c) const {
12541255
}
12551256

12561257

1257-
/// Position::is_draw() tests whether the position is drawn by material,
1258-
/// repetition, or the 50 moves rule. It does not detect stalemates, this
1259-
/// must be done by the search.
1260-
bool Position::is_draw() const {
1258+
/// Position::is_draw() tests whether the position is drawn by repetition
1259+
/// or the 50 moves rule. It does not detect stalemates, this must be done
1260+
/// by the search.
12611261

1262-
// Draw by material?
1263-
if ( !pieces(PAWN)
1264-
&& (non_pawn_material(WHITE) + non_pawn_material(BLACK) <= BishopValueMg))
1265-
return true;
1262+
bool Position::is_draw() const {
12661263

12671264
// Draw by the 50 moves rule?
12681265
if (st->rule50 > 99 && (!checkers() || MoveList<LEGAL>(*this).size()))

0 commit comments

Comments
 (0)