X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fsearch.cpp;h=22d5d647447d520accc4c23ec785766e6abfde0b;hp=669302fcfa22997feaae32bf4f196fc077f64195;hb=35e39a196d0d0bc135a5e6acbfbb6130c832e004;hpb=9643d7524ee905e09491b1bc558ee3d0f6e1d16f diff --git a/src/search.cpp b/src/search.cpp index 669302fc..22d5d647 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -1025,8 +1025,8 @@ namespace { // search<>() is the main search function for both PV and non-PV nodes template - Value search(Position& pos, SearchStack ss[], Value alpha, Value beta, - Depth depth, int ply, bool allowNullmove, int threadID, Move excludedMove) { + Value search(Position& pos, SearchStack ss[], Value alpha, Value beta, Depth depth, + int ply, bool allowNullmove, int threadID, Move excludedMove) { assert(alpha >= -VALUE_INFINITE && alpha <= VALUE_INFINITE); assert(beta > alpha && beta <= VALUE_INFINITE); @@ -1098,7 +1098,7 @@ namespace { isCheck = pos.is_check(); if (!isCheck) { - if (!PvNode && tte && (tte->type() & VALUE_TYPE_EVAL)) + if (tte && (tte->type() & VALUE_TYPE_EVAL)) ss[ply].eval = value_from_tt(tte->value(), ply); else ss[ply].eval = evaluate(pos, ei, threadID); @@ -1247,9 +1247,10 @@ namespace { if (abs(ttValue) < VALUE_KNOWN_WIN) { - Value excValue = search(pos, ss, ttValue - SingularExtensionMargin - 1, ttValue - SingularExtensionMargin, depth / 2, ply, false, threadID, move); + Value b = ttValue - SingularExtensionMargin; + Value v = search(pos, ss, b - 1, b, depth / 2, ply, false, threadID, move); - if (excValue < ttValue - SingularExtensionMargin) + if (v < ttValue - SingularExtensionMargin) ext = OnePly; } } @@ -1274,7 +1275,7 @@ namespace { continue; // Value based pruning - Depth predictedDepth = newDepth - reduction(depth, moveCount); // We illogically ignore reduction condition depth >= 3*OnePly + Depth predictedDepth = newDepth - reduction(depth, moveCount); // FIXME We illogically ignore reduction condition depth >= 3*OnePly futilityValueScaled = ss[ply].eval + futility_margin(predictedDepth, moveCount) + H.gain(pos.piece_on(move_from(move)), move_to(move)); @@ -1295,34 +1296,36 @@ namespace { value = -search(pos, ss, -beta, -alpha, newDepth, ply+1, false, threadID); else { - // Step 14. Reduced search - // if the move fails high will be re-searched at full depth. - bool doFullDepthSearch = true; - - if ( depth >= 3 * OnePly - && !dangerous - && !captureOrPromotion - && !move_is_castle(move) - && !move_is_killer(move, ss[ply])) - { - ss[ply].reduction = reduction(depth, moveCount); - if (ss[ply].reduction) - { - value = -search(pos, ss, -(alpha+1), -alpha, newDepth-ss[ply].reduction, ply+1, true, threadID); - doFullDepthSearch = (value > alpha); - } - } - - // Step 15. Full depth search - if (doFullDepthSearch) - { - ss[ply].reduction = Depth(0); - value = -search(pos, ss, -(alpha+1), -alpha, newDepth, ply+1, true, threadID); + // Step 14. Reduced search + // if the move fails high will be re-searched at full depth. + bool doFullDepthSearch = true; + + if ( depth >= 3 * OnePly + && !dangerous + && !captureOrPromotion + && !move_is_castle(move) + && !move_is_killer(move, ss[ply])) + { + ss[ply].reduction = reduction(depth, moveCount); + if (ss[ply].reduction) + { + value = -search(pos, ss, -(alpha+1), -alpha, newDepth-ss[ply].reduction, ply+1, true, threadID); + doFullDepthSearch = (value > alpha); + } + } - // Step extra. pv search (only in PV nodes) - if (PvNode && value > alpha && value < beta) - value = -search(pos, ss, -beta, -alpha, newDepth, ply+1, false, threadID); - } + // Step 15. Full depth search + if (doFullDepthSearch) + { + ss[ply].reduction = Depth(0); + value = -search(pos, ss, -(alpha+1), -alpha, newDepth, ply+1, true, threadID); + + // Step extra. pv search (only in PV nodes) + // Search only for possible new PV nodes, if instead value >= beta then + // parent node fails low with value <= alpha and tries another move. + if (PvNode && value > alpha && value < beta) + value = -search(pos, ss, -beta, -alpha, newDepth, ply+1, false, threadID); + } } // Step 16. Undo move