From f0de8dc0349bac56021a900910f14a00a729dbc6 Mon Sep 17 00:00:00 2001 From: Carlos Esparza Date: Mon, 21 Apr 2025 18:26:46 -0700 Subject: [PATCH] Simplify move ordering bonuses for putting piece en prise and escaping capture Now there is also a penalty for exposing knights and bishops to capture by a pawn. Passed STC: https://tests.stockfishchess.org/tests/view/68074379878abf56f9a0d5b1 LLR: 2.94 (-2.94,2.94) <-1.75,0.25> Total: 96512 W: 24841 L: 24687 D: 46984 Ptnml(0-2): 294, 11336, 24835, 11504, 287 Passed LTC: https://tests.stockfishchess.org/tests/view/6808954a878abf56f9a0d76d LLR: 2.95 (-2.94,2.94) <-1.75,0.25> Total: 221328 W: 56271 L: 56255 D: 108802 Ptnml(0-2): 131, 24149, 62071, 24199, 114 closes https://github.com/official-stockfish/Stockfish/pull/6023 Bench: 1778227 --- src/movepick.cpp | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/src/movepick.cpp b/src/movepick.cpp index cac4abe4a..71a5f9959 100644 --- a/src/movepick.cpp +++ b/src/movepick.cpp @@ -126,21 +126,20 @@ void MovePicker::score() { static_assert(Type == CAPTURES || Type == QUIETS || Type == EVASIONS, "Wrong type"); - [[maybe_unused]] Bitboard threatenedByPawn, threatenedByMinor, threatenedByRook, - threatenedPieces; + [[maybe_unused]] Bitboard threatenedPieces, threatByLesser[4]; if constexpr (Type == QUIETS) { Color us = pos.side_to_move(); - threatenedByPawn = pos.attacks_by(~us); - threatenedByMinor = - pos.attacks_by(~us) | pos.attacks_by(~us) | threatenedByPawn; - threatenedByRook = pos.attacks_by(~us) | threatenedByMinor; + threatByLesser[0] = threatByLesser[1] = pos.attacks_by(~us); + threatByLesser[2] = + pos.attacks_by(~us) | pos.attacks_by(~us) | threatByLesser[0]; + threatByLesser[3] = pos.attacks_by(~us) | threatByLesser[2]; // Pieces threatened by pieces of lesser material value - threatenedPieces = (pos.pieces(us, QUEEN) & threatenedByRook) - | (pos.pieces(us, ROOK) & threatenedByMinor) - | (pos.pieces(us, KNIGHT, BISHOP) & threatenedByPawn); + threatenedPieces = (pos.pieces(us, QUEEN) & threatByLesser[3]) + | (pos.pieces(us, ROOK) & threatByLesser[2]) + | (pos.pieces(us, KNIGHT, BISHOP) & threatByLesser[0]); } for (auto& m : *this) @@ -172,17 +171,15 @@ void MovePicker::score() { // bonus for checks m.value += (bool(pos.check_squares(pt) & to) && pos.see_ge(m, -75)) * 16384; - // bonus for escaping from capture - m.value += threatenedPieces & from ? (pt == QUEEN && !(to & threatenedByRook) ? 51700 - : pt == ROOK && !(to & threatenedByMinor) ? 25600 - : !(to & threatenedByPawn) ? 14450 - : 0) - : 0; - - // malus for putting piece en prise - m.value -= (pt == QUEEN && bool(to & threatenedByRook) ? 49000 - : pt == ROOK && bool(to & threatenedByMinor) ? 24335 - : 0); + // penalty for moving to a square threatened by a lesser piece + // or bonus for escaping an attack by a lesser piece. + constexpr int bonus[4] = {144, 144, 256, 517}; + if (KNIGHT <= pt && pt <= QUEEN) + { + auto i = pt - 2; + int v = (threatByLesser[i] & to ? -95 : 100 * bool(threatByLesser[i] & from)); + m.value += bonus[i] * v; + } if (ply < LOW_PLY_HISTORY_SIZE) m.value += 8 * (*lowPlyHistory)[ply][m.from_to()] / (1 + 2 * ply);