X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fsearch.cpp;h=1ffe1e97adb7291f532c1dce631adaad22f6a86c;hp=2fa2ce7e27cb4e41c0243a8f55f987b3d8f2dd35;hb=847bc0e80fa78a81b028515da03a90ea4dd40458;hpb=a47bbca0ea40ac007d64682c3ba51fa4158b2d3f diff --git a/src/search.cpp b/src/search.cpp index 2fa2ce7e..1ffe1e97 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -162,7 +162,7 @@ namespace { Value DrawValue[COLOR_NB]; template - 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, bool cutNode, bool skipEarlyPruning); template Value qsearch(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth); @@ -407,7 +407,7 @@ void Thread::search() { // high/low anymore. while (true) { - bestValue = ::search(rootPos, ss, alpha, beta, rootDepth, false); + bestValue = ::search(rootPos, ss, alpha, beta, rootDepth, false, 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 @@ -541,7 +541,7 @@ namespace { // search<>() is the main search function for both PV and non-PV nodes template - 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, bool cutNode, bool skipEarlyPruning) { const bool PvNode = NT == PV; const bool rootNode = PvNode && (ss-1)->ply == 0; @@ -617,7 +617,6 @@ namespace { ss->currentMove = (ss+1)->excludedMove = bestMove = MOVE_NONE; ss->counterMoves = nullptr; - (ss+1)->skipEarlyPruning = false; (ss+2)->killers[0] = (ss+2)->killers[1] = MOVE_NONE; Square prevSq = to_sq((ss-1)->currentMove); @@ -712,7 +711,7 @@ namespace { ss->staticEval, TT.generation()); } - if (ss->skipEarlyPruning) + if (skipEarlyPruning) goto moves_loop; // Step 6. Razoring (skipped when in check) @@ -753,10 +752,8 @@ namespace { Depth R = ((823 + 67 * depth / ONE_PLY) / 256 + std::min((eval - beta) / PawnValueMg, 3)) * ONE_PLY; pos.do_null_move(st); - (ss+1)->skipEarlyPruning = true; nullValue = depth-R < ONE_PLY ? -qsearch(pos, ss+1, -beta, -beta+1, DEPTH_ZERO) - : - search(pos, ss+1, -beta, -beta+1, depth-R, !cutNode); - (ss+1)->skipEarlyPruning = false; + : - search(pos, ss+1, -beta, -beta+1, depth-R, !cutNode, true); pos.undo_null_move(); if (nullValue >= beta) @@ -769,10 +766,8 @@ namespace { return nullValue; // Do verification search at high depths - ss->skipEarlyPruning = true; Value v = depth-R < ONE_PLY ? qsearch(pos, ss, beta-1, beta, DEPTH_ZERO) - : search(pos, ss, beta-1, beta, depth-R, false); - ss->skipEarlyPruning = false; + : search(pos, ss, beta-1, beta, depth-R, false, true); if (v >= beta) return nullValue; @@ -801,7 +796,7 @@ namespace { ss->currentMove = move; ss->counterMoves = &thisThread->counterMoveHistory[pos.moved_piece(move)][to_sq(move)]; pos.do_move(move, st); - value = -search(pos, ss+1, -rbeta, -rbeta+1, rdepth, !cutNode); + value = -search(pos, ss+1, -rbeta, -rbeta+1, rdepth, !cutNode, false); pos.undo_move(move); if (value >= rbeta) return value; @@ -814,9 +809,7 @@ namespace { && (PvNode || ss->staticEval + 256 >= beta)) { Depth d = (3 * depth / (4 * ONE_PLY) - 2) * ONE_PLY; - ss->skipEarlyPruning = true; - search(pos, ss, alpha, beta, d, cutNode); - ss->skipEarlyPruning = false; + search(pos, ss, alpha, beta, d, cutNode, true); tte = TT.probe(posKey, ttHit); ttMove = ttHit ? tte->move() : MOVE_NONE; @@ -898,9 +891,7 @@ moves_loop: // When in check search starts from here Value rBeta = std::max(ttValue - 2 * depth / ONE_PLY, -VALUE_MATE); Depth d = (depth / (2 * ONE_PLY)) * ONE_PLY; ss->excludedMove = move; - ss->skipEarlyPruning = true; - value = search(pos, ss, rBeta - 1, rBeta, d, cutNode); - ss->skipEarlyPruning = false; + value = search(pos, ss, rBeta - 1, rBeta, d, cutNode, true); ss->excludedMove = MOVE_NONE; if (value < rBeta) @@ -945,11 +936,7 @@ moves_loop: // When in check search starts from here } else if (depth < 7 * ONE_PLY && !extension) { - Value v = -Value(399 + 35 * depth / ONE_PLY * depth / ONE_PLY); - - if (PvNode) - v += beta - alpha - 1; - + Value v = -Value(400 - 100 * PvNode + 35 * depth / ONE_PLY * depth / ONE_PLY); if (!pos.see_ge(move, v)) continue; } @@ -1014,7 +1001,7 @@ moves_loop: // When in check search starts from here Depth d = std::max(newDepth - r, ONE_PLY); - value = -search(pos, ss+1, -(alpha+1), -alpha, d, true); + value = -search(pos, ss+1, -(alpha+1), -alpha, d, true, false); doFullDepthSearch = (value > alpha && d != newDepth); } @@ -1026,7 +1013,7 @@ moves_loop: // When in check search starts from here value = newDepth < ONE_PLY ? givesCheck ? -qsearch(pos, ss+1, -(alpha+1), -alpha, DEPTH_ZERO) : -qsearch(pos, ss+1, -(alpha+1), -alpha, DEPTH_ZERO) - : - search(pos, ss+1, -(alpha+1), -alpha, newDepth, !cutNode); + : - 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 @@ -1039,7 +1026,7 @@ moves_loop: // When in check search starts from here value = newDepth < ONE_PLY ? givesCheck ? -qsearch(pos, ss+1, -beta, -alpha, DEPTH_ZERO) : -qsearch(pos, ss+1, -beta, -alpha, DEPTH_ZERO) - : - search(pos, ss+1, -beta, -alpha, newDepth, false); + : - search(pos, ss+1, -beta, -alpha, newDepth, false, false); } // Step 17. Undo move