From: Joost VandeVondele Date: Sun, 11 Dec 2016 19:05:25 +0000 (+0100) Subject: Clean-up skipEarlyPruning (#921) X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=1b62d413c137bfa669922b6d52b92262d60020f1 Clean-up skipEarlyPruning (#921) make skipEarlyPruning a search argument instead of managing this by hand. Verified for no regression at STC: LLR: 2.96 (-2.94,2.94) [-3.00,1.00] Total: 96754 W: 17089 L: 17095 D: 62570 No functional change. --- diff --git a/src/search.cpp b/src/search.cpp index 2fa2ce7e..57f63653 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) @@ -1014,7 +1005,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 +1017,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 +1030,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 diff --git a/src/search.h b/src/search.h index d8051ec0..c2d5d8e9 100644 --- a/src/search.h +++ b/src/search.h @@ -38,15 +38,14 @@ namespace Search { struct Stack { Move* pv; + CounterMoveStats* counterMoves; int ply; Move currentMove; Move excludedMove; Move killers[2]; Value staticEval; Value history; - bool skipEarlyPruning; int moveCount; - CounterMoveStats* counterMoves; };