]> git.sesse.net Git - stockfish/commitdiff
Malus during move ordering for putting pieces en prise
authorrn5f107s2 <clemens.lerchl@gmail.com>
Wed, 26 Jul 2023 12:31:16 +0000 (14:31 +0200)
committerStéphane Nicolet <cassio@free.fr>
Fri, 28 Jul 2023 22:56:26 +0000 (00:56 +0200)
The original idea is the reverse of a previous patch [1] which added bonuses
in our move picker to moves escaping threats. In this patch, in addition to
bonuses for evading threats, we apply penalties to moves moving to threatened
squares.

Further tweaks of that basic idea resulted in this specific version which
further increases the penalty of moves moving to squares threatend depending
on the piece threatening it. So for example a queen moving to a square attacked
by a pawn would receive a larger penalty than a queen moving to square attacked
by a rook.

[1]: https://github.com/official-stockfish/Stockfish/commit/08e0f52b77edb929989c68c49e954b9bc5d7d67e

--------

Passed STC:
https://tests.stockfishchess.org/tests/live_elo/64c11269dc56e1650abb935d
LLR: 2.94 (-2.94,2.94) <0.00,2.00>
Total: 95552 W: 24654 L: 24250 D: 46648
Ptnml(0-2): 322, 11098, 24562, 11442, 352

Passed LTC:
https://tests.stockfishchess.org/tests/live_elo/64c2004ddc56e1650abba8b3
LLR: 2.94 (-2.94,2.94) <0.50,2.50>
Total: 190230 W: 48806 L: 48178 D: 93246
Ptnml(0-2): 90, 20439, 53453, 21019, 114

-------

closes https://github.com/official-stockfish/Stockfish/pull/4711

Bench: 1350831

src/movepick.cpp

index 6fbcb2c3d2fec925078b7a9717080d0a3dd6f90b..4050810338fd1e3d5ce840bdbae86b10ca3fc84e 100644 (file)
@@ -123,21 +123,45 @@ void MovePicker::score() {
   for (auto& m : *this)
       if constexpr (Type == CAPTURES)
           m.value =  (7 * int(PieceValue[MG][pos.piece_on(to_sq(m))])
-                   +     (*captureHistory)[pos.moved_piece(m)][to_sq(m)][type_of(pos.piece_on(to_sq(m)))]) / 16;
+                   + (*captureHistory)[pos.moved_piece(m)][to_sq(m)][type_of(pos.piece_on(to_sq(m)))]) / 16;
 
       else if constexpr (Type == QUIETS)
-          m.value =  2 * (*mainHistory)[pos.side_to_move()][from_to(m)]
-                   + 2 * (*continuationHistory[0])[pos.moved_piece(m)][to_sq(m)]
-                   +     (*continuationHistory[1])[pos.moved_piece(m)][to_sq(m)]
-                   +     (*continuationHistory[3])[pos.moved_piece(m)][to_sq(m)]
-                   +     (*continuationHistory[5])[pos.moved_piece(m)][to_sq(m)]
-                   +     (threatenedPieces & from_sq(m) ?
-                           (type_of(pos.moved_piece(m)) == QUEEN && !(to_sq(m) & threatenedByRook)  ? 50000
-                          : type_of(pos.moved_piece(m)) == ROOK  && !(to_sq(m) & threatenedByMinor) ? 25000
-                          :                                         !(to_sq(m) & threatenedByPawn)  ? 15000
-                          :                                                                           0)
-                          :                                                                           0)
-                   +     bool(pos.check_squares(type_of(pos.moved_piece(m))) & to_sq(m)) * 16384;
+      {
+          Piece     pc   = pos.moved_piece(m);
+          PieceType pt   = type_of(pos.moved_piece(m));
+          Square    from = from_sq(m);
+          Square    to   = to_sq(m);
+
+          // histories
+          m.value =  2 * (*mainHistory)[pos.side_to_move()][from_to(m)];
+          m.value += 2 * (*continuationHistory[0])[pc][to];
+          m.value +=     (*continuationHistory[1])[pc][to];
+          m.value +=     (*continuationHistory[3])[pc][to];
+          m.value +=     (*continuationHistory[5])[pc][to];
+
+          // bonus for checks
+          m.value += bool(pos.check_squares(pt) & to) * 16384;
+
+          // bonus for escaping from capture
+          m.value += threatenedPieces & from ?
+                       (pt == QUEEN && !(to & threatenedByRook)  ? 50000
+                      : pt == ROOK  && !(to & threatenedByMinor) ? 25000
+                      :                !(to & threatenedByPawn)  ? 15000
+                      :                                            0 )
+                      :                                            0 ;
+
+          // malus for putting piece en prise
+          m.value -= !(threatenedPieces & from) ?
+                        (pt == QUEEN ?   bool(to & threatenedByRook)  * 50000
+                                       + bool(to & threatenedByMinor) * 10000
+                                       + bool(to & threatenedByPawn)  * 20000
+                       : pt == ROOK  ?   bool(to & threatenedByMinor) * 25000
+                                       + bool(to & threatenedByPawn)  * 10000
+                       : pt != PAWN ?    bool(to & threatenedByPawn)  * 15000
+                       :                                                0 )
+                       :                                                0 ;
+      }
+      
       else // Type == EVASIONS
       {
           if (pos.capture_stage(m))