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);