Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do more reductions for late quiet moves in case of consecutive fail highs. #3184

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 13 additions & 11 deletions src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ namespace {
};

template <NodeType NT>
Value search(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth, bool cutNode);
Value search(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth, int failedHighCnt, bool cutNode);

template <NodeType NT>
Value qsearch(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth = 0);
Expand Down Expand Up @@ -421,7 +421,7 @@ void Thread::search() {
while (true)
{
Depth adjustedDepth = std::max(1, rootDepth - failedHighCnt - searchAgainCounter);
bestValue = ::search<PV>(rootPos, ss, alpha, beta, adjustedDepth, false);
bestValue = ::search<PV>(rootPos, ss, alpha, beta, adjustedDepth, failedHighCnt, false);

// Bring the best move to the front. It is critical that sorting
// is done with a stable algorithm because all the values but the
Expand Down Expand Up @@ -561,7 +561,7 @@ namespace {
// search<>() is the main search function for both PV and non-PV nodes

template <NodeType NT>
Value search(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth, bool cutNode) {
Value search(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth, int failedHighCnt, bool cutNode) {

constexpr bool PvNode = NT == PV;
const bool rootNode = PvNode && ss->ply == 0;
Expand Down Expand Up @@ -836,7 +836,7 @@ namespace {

pos.do_null_move(st);

Value nullValue = -search<NonPV>(pos, ss+1, -beta, -beta+1, depth-R, !cutNode);
Value nullValue = -search<NonPV>(pos, ss+1, -beta, -beta+1, depth-R, 0, !cutNode);

pos.undo_null_move();

Expand All @@ -856,7 +856,7 @@ namespace {
thisThread->nmpMinPly = ss->ply + 3 * (depth-R) / 4;
thisThread->nmpColor = us;

Value v = search<NonPV>(pos, ss, beta-1, beta, depth-R, false);
Value v = search<NonPV>(pos, ss, beta-1, beta, depth-R, 0, false);

thisThread->nmpMinPly = 0;

Expand Down Expand Up @@ -921,7 +921,7 @@ namespace {

// If the qsearch held, perform the regular search
if (value >= probCutBeta)
value = -search<NonPV>(pos, ss+1, -probCutBeta, -probCutBeta+1, depth - 4, !cutNode);
value = -search<NonPV>(pos, ss+1, -probCutBeta, -probCutBeta+1, depth - 4, 0, !cutNode);

pos.undo_move(move);

Expand Down Expand Up @@ -1074,7 +1074,7 @@ namespace {
Value singularBeta = ttValue - ((formerPv + 4) * depth) / 2;
Depth singularDepth = (depth - 1 + 3 * formerPv) / 2;
ss->excludedMove = move;
value = search<NonPV>(pos, ss, singularBeta - 1, singularBeta, singularDepth, cutNode);
value = search<NonPV>(pos, ss, singularBeta - 1, singularBeta, singularDepth, 0, cutNode);
ss->excludedMove = MOVE_NONE;

if (value < singularBeta)
Expand All @@ -1096,7 +1096,7 @@ namespace {
else if (ttValue >= beta)
{
ss->excludedMove = move;
value = search<NonPV>(pos, ss, beta - 1, beta, (depth + 3) / 2, cutNode);
value = search<NonPV>(pos, ss, beta - 1, beta, (depth + 3) / 2, 0, cutNode);
ss->excludedMove = MOVE_NONE;

if (value >= beta)
Expand Down Expand Up @@ -1177,6 +1177,8 @@ namespace {
if (ttCapture)
r++;

r += failedHighCnt * failedHighCnt * moveCount / 512;

// Increase reduction for cut nodes (~10 Elo)
if (cutNode)
r += 2;
Expand Down Expand Up @@ -1218,7 +1220,7 @@ namespace {

Depth d = std::clamp(newDepth - r, 1, newDepth);

value = -search<NonPV>(pos, ss+1, -(alpha+1), -alpha, d, true);
value = -search<NonPV>(pos, ss+1, -(alpha+1), -alpha, d, 0, true);

doFullDepthSearch = value > alpha && d != newDepth;

Expand All @@ -1234,7 +1236,7 @@ namespace {
// Step 17. Full depth search when LMR is skipped or fails high
if (doFullDepthSearch)
{
value = -search<NonPV>(pos, ss+1, -(alpha+1), -alpha, newDepth, !cutNode);
value = -search<NonPV>(pos, ss+1, -(alpha+1), -alpha, newDepth, 0, !cutNode);

if (didLMR && !captureOrPromotion)
{
Expand All @@ -1256,7 +1258,7 @@ namespace {
(ss+1)->pv = pv;
(ss+1)->pv[0] = MOVE_NONE;

value = -search<PV>(pos, ss+1, -beta, -alpha, newDepth, false);
value = -search<PV>(pos, ss+1, -beta, -alpha, newDepth, 0, false);
}

// Step 18. Undo move
Expand Down