Skip to content

Commit a7ab92e

Browse files
dsmsgmssnicolet
authored andcommitted
Use classical eval for Bishop vs Pawns
NNUE evaluation is incapable of recognizing trivially drawn bishop endgames (the wrong-colored rook pawn), which are in fact ubiquitous and stock standard in chess analysis. Switching off NNUE evaluation in KBPs vs KPs endgames is a measure that stops Stockfish from trading down to a drawn version of these endings when we presumably have advantage. The patch is able to edge over master in endgame positions. Patch tested for Elo gain with the "endgame.epd" book, and verified for non-regression with our usual book (see the pull request for details). STC: LLR: 2.93 (-2.94,2.94) {-0.20,1.10} Total: 33232 W: 6655 L: 6497 D: 20080 Ptnml(0-2): 4, 2342, 11769, 2494, 7 https://tests.stockfishchess.org/tests/view/6074a52981417533789605b8 LTC: LLR: 2.93 (-2.94,2.94) {0.20,0.90} Total: 159056 W: 29799 L: 29378 D: 99879 Ptnml(0-2): 7, 9004, 61085, 9425, 7 https://tests.stockfishchess.org/tests/view/6074c39a81417533789605ca Closes #3427 Bench: 4503918 blah
1 parent 255514f commit a7ab92e

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/evaluate.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,23 +1104,26 @@ Value Eval::evaluate(const Position& pos) {
11041104
return nnue;
11051105
};
11061106

1107-
// If there is PSQ imbalance use classical eval, with small probability if it is small
1107+
// If there is PSQ imbalance we use the classical eval. We also introduce
1108+
// a small probability of using the classical eval when PSQ imbalance is small.
11081109
Value psq = Value(abs(eg_value(pos.psq_score())));
11091110
int r50 = 16 + pos.rule50_count();
11101111
bool largePsq = psq * 16 > (NNUEThreshold1 + pos.non_pawn_material() / 64) * r50;
11111112
bool classical = largePsq || (psq > PawnValueMg / 4 && !(pos.this_thread()->nodes & 0xB));
11121113

11131114
// Use classical evaluation for really low piece endgames.
1114-
// The most critical case is a bishop + A/H file pawn vs naked king draw.
1115-
bool strongClassical = pos.non_pawn_material() < 2 * RookValueMg && pos.count<PAWN>() < 2;
1115+
// One critical case is the draw for bishop + A/H file pawn vs naked king.
1116+
bool lowPieceEndgame = pos.non_pawn_material() == BishopValueMg
1117+
|| (pos.non_pawn_material() < 2 * RookValueMg && pos.count<PAWN>() < 2);
11161118

1117-
v = classical || strongClassical ? Evaluation<NO_TRACE>(pos).value() : adjusted_NNUE();
1119+
v = classical || lowPieceEndgame ? Evaluation<NO_TRACE>(pos).value()
1120+
: adjusted_NNUE();
11181121

11191122
// If the classical eval is small and imbalance large, use NNUE nevertheless.
1120-
// For the case of opposite colored bishops, switch to NNUE eval with
1121-
// small probability if the classical eval is less than the threshold.
1122-
if ( largePsq
1123-
&& !strongClassical
1123+
// For the case of opposite colored bishops, switch to NNUE eval with small
1124+
// probability if the classical eval is less than the threshold.
1125+
if ( largePsq
1126+
&& !lowPieceEndgame
11241127
&& ( abs(v) * 16 < NNUEThreshold2 * r50
11251128
|| ( pos.opposite_bishops()
11261129
&& abs(v) * 16 < (NNUEThreshold1 + pos.non_pawn_material() / 64) * r50

0 commit comments

Comments
 (0)