Skip to content

Commit f436bf7

Browse files
Disservinsnicolet
authored andcommitted
Use less reduction for escaping moves
This patch reuses the threatenedPieces variable (which is calculated in movepicker) to reduce less in the search tree the moves which escape a capture. passed STC: LLR: 2.94 (-2.94,2.94) <0.00,2.00> Total: 314352 W: 84042 L: 83328 D: 146982 Ptnml(0-2): 1105, 35084, 84207, 35552, 1228 https://tests.stockfishchess.org/tests/view/63355f37a004bed9a2e4a17f passed LTC: LLR: 2.95 (-2.94,2.94) <0.50,2.50> Total: 90752 W: 24556 L: 24147 D: 42049 Ptnml(0-2): 59, 8855, 27123, 9296, 43 https://tests.stockfishchess.org/tests/view/63383a7735f43d649ff5fa8b closes #4181 bench: 4114228
1 parent 232bf19 commit f436bf7

File tree

6 files changed

+21
-15
lines changed

6 files changed

+21
-15
lines changed

src/evaluate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ Value Eval::evaluate(const Position& pos, int* complexity) {
10541054
Color stm = pos.side_to_move();
10551055
Value psq = pos.psq_eg_stm();
10561056

1057-
// We use the much less accurate but faster Classical eval when the NNUE
1057+
// We use the much less accurate but faster Classical eval when the NNUE
10581058
// option is set to false. Otherwise we use the NNUE eval unless the
10591059
// PSQ advantage is decisive and several pieces remain (~3 Elo)
10601060
bool useClassical = !useNNUE || (pos.count<ALL_PIECES>() > 7 && abs(psq) > 1760);

src/movepick.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const ButterflyHist
6969

7070
stage = (pos.checkers() ? EVASION_TT : MAIN_TT) +
7171
!(ttm && pos.pseudo_legal(ttm));
72+
threatenedPieces = 0;
7273
}
7374

7475
/// MovePicker constructor for quiescence search
@@ -106,21 +107,19 @@ void MovePicker::score() {
106107

107108
static_assert(Type == CAPTURES || Type == QUIETS || Type == EVASIONS, "Wrong type");
108109

109-
[[maybe_unused]] Bitboard threatened, threatenedByPawn, threatenedByMinor, threatenedByRook;
110+
[[maybe_unused]] Bitboard threatenedByPawn, threatenedByMinor, threatenedByRook;
110111
if constexpr (Type == QUIETS)
111112
{
112113
Color us = pos.side_to_move();
113-
// squares threatened by pawns
114+
114115
threatenedByPawn = pos.attacks_by<PAWN>(~us);
115-
// squares threatened by minors or pawns
116116
threatenedByMinor = pos.attacks_by<KNIGHT>(~us) | pos.attacks_by<BISHOP>(~us) | threatenedByPawn;
117-
// squares threatened by rooks, minors or pawns
118117
threatenedByRook = pos.attacks_by<ROOK>(~us) | threatenedByMinor;
119118

120-
// pieces threatened by pieces of lesser material value
121-
threatened = (pos.pieces(us, QUEEN) & threatenedByRook)
122-
| (pos.pieces(us, ROOK) & threatenedByMinor)
123-
| (pos.pieces(us, KNIGHT, BISHOP) & threatenedByPawn);
119+
// Pieces threatened by pieces of lesser material value
120+
threatenedPieces = (pos.pieces(us, QUEEN) & threatenedByRook)
121+
| (pos.pieces(us, ROOK) & threatenedByMinor)
122+
| (pos.pieces(us, KNIGHT, BISHOP) & threatenedByPawn);
124123
}
125124

126125
for (auto& m : *this)
@@ -134,7 +133,7 @@ void MovePicker::score() {
134133
+ (*continuationHistory[1])[pos.moved_piece(m)][to_sq(m)]
135134
+ (*continuationHistory[3])[pos.moved_piece(m)][to_sq(m)]
136135
+ (*continuationHistory[5])[pos.moved_piece(m)][to_sq(m)]
137-
+ (threatened & from_sq(m) ?
136+
+ (threatenedPieces & from_sq(m) ?
138137
(type_of(pos.moved_piece(m)) == QUEEN && !(to_sq(m) & threatenedByRook) ? 50000
139138
: type_of(pos.moved_piece(m)) == ROOK && !(to_sq(m) & threatenedByMinor) ? 25000
140139
: !(to_sq(m) & threatenedByPawn) ? 15000

src/movepick.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ class MovePicker {
131131
MovePicker(const Position&, Move, Value, Depth, const CapturePieceToHistory*);
132132
Move next_move(bool skipQuiets = false);
133133

134+
Bitboard threatenedPieces;
135+
134136
private:
135137
template<PickType T, typename Pred> Move select(Pred);
136138
template<GenType> void score();

src/search.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ namespace {
789789
&& depth < 8
790790
&& eval - futility_margin(depth, improving) - (ss-1)->statScore / 303 >= beta
791791
&& eval >= beta
792-
&& eval < 28031) // larger than VALUE_KNOWN_WIN, but smaller than TB wins.
792+
&& eval < 28031) // larger than VALUE_KNOWN_WIN, but smaller than TB wins
793793
return eval;
794794

795795
// Step 9. Null move search with verification search (~22 Elo)
@@ -1163,7 +1163,12 @@ namespace {
11631163
if (singularQuietLMR)
11641164
r--;
11651165

1166-
// Increase reduction if next ply has a lot of fail high else reset count to 0
1166+
// Dicrease reduction if we move a threatened piece (~1 Elo)
1167+
if ( depth > 9
1168+
&& (mp.threatenedPieces & from_sq(move)))
1169+
r--;
1170+
1171+
// Increase reduction if next ply has a lot of fail high
11671172
if ((ss+1)->cutoffCnt > 3 && !PvNode)
11681173
r++;
11691174

src/thread.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void Thread::clear() {
6161
mainHistory.fill(0);
6262
captureHistory.fill(0);
6363
previousDepth = 0;
64-
64+
6565
for (bool inCheck : { false, true })
6666
for (StatsType c : { NoCaptures, Captures })
6767
{

src/uci.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ namespace {
224224

225225
/// UCI::loop() waits for a command from the stdin, parses it and then calls the appropriate
226226
/// function. It also intercepts an end-of-file (EOF) indication from the stdin to ensure a
227-
/// graceful exit if the GUI dies unexpectedly. When called with some command-line arguments,
227+
/// graceful exit if the GUI dies unexpectedly. When called with some command-line arguments,
228228
/// like running 'bench', the function returns immediately after the command is executed.
229229
/// In addition to the UCI ones, some additional debug commands are also supported.
230230

@@ -240,7 +240,7 @@ void UCI::loop(int argc, char* argv[]) {
240240
cmd += std::string(argv[i]) + " ";
241241

242242
do {
243-
if (argc == 1 && !getline(cin, cmd)) // Wait for an input or an end-of-file (EOF) indication
243+
if (argc == 1 && !getline(cin, cmd)) // Wait for an input or an end-of-file (EOF) indication
244244
cmd = "quit";
245245

246246
istringstream is(cmd);

0 commit comments

Comments
 (0)