- if (!captureOrPromotion)
- {
- // Increase reduction if ttMove is a capture (~0 Elo)
- if (ttCapture)
- r += ONE_PLY;
-
- // Increase reduction for cut nodes (~5 Elo)
- if (cutNode)
- r += 2 * ONE_PLY;
-
- // Decrease reduction for moves that escape a capture. Filter out
- // castling moves, because they are coded as "king captures rook" and
- // hence break make_move(). (~5 Elo)
- else if ( type_of(move) == NORMAL
- && !pos.see_ge(make_move(to_sq(move), from_sq(move))))
- r -= 2 * ONE_PLY;
-
- ss->statScore = thisThread->mainHistory[us][from_to(move)]
- + (*contHist[0])[movedPiece][to_sq(move)]
- + (*contHist[1])[movedPiece][to_sq(move)]
- + (*contHist[3])[movedPiece][to_sq(move)]
- - 4000;
-
- // Decrease/increase reduction by comparing opponent's stat score (~10 Elo)
- if (ss->statScore >= 0 && (ss-1)->statScore < 0)
- r -= ONE_PLY;
-
- else if ((ss-1)->statScore >= 0 && ss->statScore < 0)
- r += ONE_PLY;
-
- // Decrease/increase reduction for moves with a good/bad history (~30 Elo)
- r -= ss->statScore / 20000 * ONE_PLY;
- }
-
- Depth d = clamp(newDepth - r, ONE_PLY, newDepth);
+ // Decrease reduction if position is or has been on the PV
+ // and node is not likely to fail low. (~3 Elo)
+ if ( ss->ttPv
+ && !likelyFailLow)
+ r -= 2;
+
+ // Increase reduction at root and non-PV nodes when the best move does not change frequently
+ if ( (rootNode || !PvNode)
+ && thisThread->bestMoveChanges <= 2)
+ r++;
+
+ // Decrease reduction if opponent's move count is high (~1 Elo)
+ if ((ss-1)->moveCount > 13)
+ r--;
+
+ // Decrease reduction if ttMove has been singularly extended (~1 Elo)
+ if (singularQuietLMR)
+ r--;
+
+ // Increase reduction for cut nodes (~3 Elo)
+ if (cutNode && move != ss->killers[0])
+ r += 2;
+
+ // Increase reduction if ttMove is a capture (~3 Elo)
+ if (ttCapture)
+ r++;
+
+ ss->statScore = thisThread->mainHistory[us][from_to(move)]
+ + (*contHist[0])[movedPiece][to_sq(move)]
+ + (*contHist[1])[movedPiece][to_sq(move)]
+ + (*contHist[3])[movedPiece][to_sq(move)]
+ - 4923;
+
+ // Decrease/increase reduction for moves with a good/bad history (~30 Elo)
+ r -= ss->statScore / 14721;
+
+ // In general we want to cap the LMR depth search at newDepth. But if
+ // reductions are really negative and movecount is low, we allow this move
+ // to be searched deeper than the first move, unless ttMove was extended by 2.
+ Depth d = std::clamp(newDepth - r, 1, newDepth + (r < -1 && moveCount <= 5 && !doubleExtension));