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
This commit is contained in:
Carlos Esparza
2025-04-27 19:42:06 +02:00
committed by Disservin
parent fda269a299
commit f0de8dc034
+17 -20
View File
@@ -126,21 +126,20 @@ void MovePicker::score() {
static_assert(Type == CAPTURES || Type == QUIETS || Type == EVASIONS, "Wrong type"); static_assert(Type == CAPTURES || Type == QUIETS || Type == EVASIONS, "Wrong type");
[[maybe_unused]] Bitboard threatenedByPawn, threatenedByMinor, threatenedByRook, [[maybe_unused]] Bitboard threatenedPieces, threatByLesser[4];
threatenedPieces;
if constexpr (Type == QUIETS) if constexpr (Type == QUIETS)
{ {
Color us = pos.side_to_move(); Color us = pos.side_to_move();
threatenedByPawn = pos.attacks_by<PAWN>(~us); threatByLesser[0] = threatByLesser[1] = pos.attacks_by<PAWN>(~us);
threatenedByMinor = threatByLesser[2] =
pos.attacks_by<KNIGHT>(~us) | pos.attacks_by<BISHOP>(~us) | threatenedByPawn; pos.attacks_by<KNIGHT>(~us) | pos.attacks_by<BISHOP>(~us) | threatByLesser[0];
threatenedByRook = pos.attacks_by<ROOK>(~us) | threatenedByMinor; threatByLesser[3] = pos.attacks_by<ROOK>(~us) | threatByLesser[2];
// Pieces threatened by pieces of lesser material value // Pieces threatened by pieces of lesser material value
threatenedPieces = (pos.pieces(us, QUEEN) & threatenedByRook) threatenedPieces = (pos.pieces(us, QUEEN) & threatByLesser[3])
| (pos.pieces(us, ROOK) & threatenedByMinor) | (pos.pieces(us, ROOK) & threatByLesser[2])
| (pos.pieces(us, KNIGHT, BISHOP) & threatenedByPawn); | (pos.pieces(us, KNIGHT, BISHOP) & threatByLesser[0]);
} }
for (auto& m : *this) for (auto& m : *this)
@@ -172,17 +171,15 @@ void MovePicker::score() {
// bonus for checks // bonus for checks
m.value += (bool(pos.check_squares(pt) & to) && pos.see_ge(m, -75)) * 16384; m.value += (bool(pos.check_squares(pt) & to) && pos.see_ge(m, -75)) * 16384;
// bonus for escaping from capture // penalty for moving to a square threatened by a lesser piece
m.value += threatenedPieces & from ? (pt == QUEEN && !(to & threatenedByRook) ? 51700 // or bonus for escaping an attack by a lesser piece.
: pt == ROOK && !(to & threatenedByMinor) ? 25600 constexpr int bonus[4] = {144, 144, 256, 517};
: !(to & threatenedByPawn) ? 14450 if (KNIGHT <= pt && pt <= QUEEN)
: 0) {
: 0; auto i = pt - 2;
int v = (threatByLesser[i] & to ? -95 : 100 * bool(threatByLesser[i] & from));
// malus for putting piece en prise m.value += bonus[i] * v;
m.value -= (pt == QUEEN && bool(to & threatenedByRook) ? 49000 }
: pt == ROOK && bool(to & threatenedByMinor) ? 24335
: 0);
if (ply < LOW_PLY_HISTORY_SIZE) if (ply < LOW_PLY_HISTORY_SIZE)
m.value += 8 * (*lowPlyHistory)[ply][m.from_to()] / (1 + 2 * ply); m.value += 8 * (*lowPlyHistory)[ply][m.from_to()] / (1 + 2 * ply);