X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fsearch.cpp;h=bf34b77e5d8bd7f8ccbe0177fe4d2ae3da6e5038;hp=1be87a8107363f376a8da4404cf4761339d995af;hb=8ab12c901258064f1a9bc531477e1b706bc974fb;hpb=8db75dd9ec05410136898aa2f8c6dc720b755eb8 diff --git a/src/search.cpp b/src/search.cpp index 1be87a81..bf34b77e 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -491,6 +491,10 @@ namespace { template Value search(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth, bool cutNode, bool skipEarlyPruning) { + // Use quiescence search when needed + if (depth < ONE_PLY) + return qsearch(pos, ss, alpha, beta); + const bool PvNode = NT == PV; const bool rootNode = PvNode && ss->ply == 0; @@ -695,6 +699,7 @@ namespace { else if (eval + RazorMargin2 <= alpha) { Value ralpha = alpha - RazorMargin2; + Value v = qsearch(pos, ss, ralpha, ralpha+1); if (v <= ralpha) @@ -724,8 +729,9 @@ namespace { ss->contHistory = thisThread->contHistory[NO_PIECE][0].get(); pos.do_null_move(st); - Value nullValue = depth-R < ONE_PLY ? -qsearch(pos, ss+1, -beta, -beta+1) - : - search(pos, ss+1, -beta, -beta+1, depth-R, !cutNode, true); + + Value nullValue = -search(pos, ss+1, -beta, -beta+1, depth-R, !cutNode, true); + pos.undo_null_move(); if (nullValue >= beta) @@ -742,8 +748,7 @@ namespace { thisThread->nmp_ply = ss->ply + 3 * (depth-R) / 4; thisThread->nmp_odd = ss->ply % 2; - Value v = depth-R < ONE_PLY ? qsearch(pos, ss, beta-1, beta) - : search(pos, ss, beta-1, beta, depth-R, false, true); + Value v = search(pos, ss, beta-1, beta, depth-R, false, true); thisThread->nmp_odd = thisThread->nmp_ply = 0; @@ -1009,8 +1014,7 @@ moves_loop: // When in check, search starts from here // Step 17. Full depth search when LMR is skipped or fails high if (doFullDepthSearch) - value = newDepth < ONE_PLY ? -qsearch(pos, ss+1, -(alpha+1), -alpha) - : - search(pos, ss+1, -(alpha+1), -alpha, newDepth, !cutNode, false); + value = -search(pos, ss+1, -(alpha+1), -alpha, newDepth, !cutNode, false); // For PV nodes only, do a full PV search on the first move or after a fail // high (in the latter case search only if value < beta), otherwise let the @@ -1020,8 +1024,7 @@ moves_loop: // When in check, search starts from here (ss+1)->pv = pv; (ss+1)->pv[0] = MOVE_NONE; - value = newDepth < ONE_PLY ? -qsearch(pos, ss+1, -beta, -alpha) - : - search(pos, ss+1, -beta, -alpha, newDepth, false, false); + value = -search(pos, ss+1, -beta, -alpha, newDepth, false, false); } // Step 18. Undo move