X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fsearch.cpp;h=6bc77d3ba61224197a72a5ada11e509ef08103c6;hp=b653ef9e70f1b33dcde02a8310ea35e24ab6d288;hb=ea53006a9ded671c5f9deb27c1262d77f9722177;hpb=05a8c318b8cfc284906f6077fd934d35d891028c diff --git a/src/search.cpp b/src/search.cpp index b653ef9e..6bc77d3b 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -1359,7 +1359,7 @@ namespace { Move ttMove, move; Depth ext, newDepth; Value bestValue, staticValue, nullValue, value, futilityValue, futilityValueScaled; - bool isCheck, useFutilityPruning, singleEvasion, moveIsCheck, captureOrPromotion, dangerous; + bool isCheck, singleEvasion, moveIsCheck, captureOrPromotion, dangerous; bool mateThreat = false; int moveCount = 0; futilityValue = staticValue = bestValue = value = -VALUE_INFINITE; @@ -1403,7 +1403,7 @@ namespace { // Calculate depth dependant futility pruning parameters const int FutilityMoveCountMargin = 3 + (1 << (3 * int(depth) / 8)); - const int FutilityValueMargin = 112 * bitScanReverse32(int(depth) * int(depth) / 2); + const int PostFutilityValueMargin = 112 * bitScanReverse32(int(depth) * int(depth) / 2); // Evaluate the position statically if (!isCheck) @@ -1417,7 +1417,7 @@ namespace { } ss[ply].eval = staticValue; - futilityValue = staticValue + FutilityValueMargin; + futilityValue = staticValue + PostFutilityValueMargin; //FIXME: Remove me, only for split staticValue = refine_eval(tte, staticValue, ply); // Enhance accuracy with TT value if possible // Store gain statistics @@ -1430,8 +1430,8 @@ namespace { } // Post futility pruning - if (staticValue - FutilityValueMargin >= beta) - return (staticValue - FutilityValueMargin); + if (depth < SelectiveDepth && staticValue - PostFutilityValueMargin >= beta) + return (staticValue - PostFutilityValueMargin); // Null move search if ( allowNullmove @@ -1510,7 +1510,6 @@ namespace { // to search all moves. MovePicker mp = MovePicker(pos, ttMove, depth, H, &ss[ply]); CheckInfo ci(pos); - useFutilityPruning = depth < SelectiveDepth && !isCheck; // Loop through all legal moves until no moves remain or a beta cutoff occurs while ( bestValue < beta @@ -1556,8 +1555,31 @@ namespace { // Update current move movesSearched[moveCount++] = ss[ply].currentMove = move; + // Futility pruning for captures + Color them = opposite_color(pos.side_to_move()); + + if ( !isCheck + && newDepth < SelectiveDepth + && !dangerous + && pos.move_is_capture(move) + && !pos.move_is_check(move, ci) + && !move_is_promotion(move) + && move != ttMove + && !move_is_ep(move) + && (pos.type_of_piece_on(move_to(move)) != PAWN || !pos.pawn_is_passed(them, move_to(move)))) // Do not prune passed pawn captures + { + int preFutilityValueMargin = 0; + + if (newDepth >= OnePly) + preFutilityValueMargin = 112 * bitScanReverse32(int(newDepth) * int(newDepth) / 2); + + if (ss[ply].eval + pos.endgame_value_of_piece_on(move_to(move)) + preFutilityValueMargin + ei.futilityMargin + 90 < beta) + continue; + } + + // Futility pruning - if ( useFutilityPruning + if ( !isCheck && !dangerous && !captureOrPromotion && !move_is_castle(move) @@ -1570,13 +1592,29 @@ namespace { continue; // Value based pruning - futilityValueScaled = futilityValue - moveCount * IncrementalFutilityMargin; + Depth predictedDepth = newDepth; - if (futilityValueScaled < beta) + //FIXME HACK: awful code duplication + double red = 0.5 + ln(moveCount) * ln(depth / 2) / 3.0; + if (red >= 1.0) + predictedDepth -= int(floor(red * int(OnePly))); + + if (predictedDepth < SelectiveDepth) { - if (futilityValueScaled > bestValue) - bestValue = futilityValueScaled; - continue; + int preFutilityValueMargin = 0; + if (predictedDepth >= OnePly) + preFutilityValueMargin = 112 * bitScanReverse32(int(predictedDepth) * int(predictedDepth) / 2); + + preFutilityValueMargin += MG.retrieve(pos.piece_on(move_from(move)), move_from(move), move_to(move)) + 45; + + futilityValueScaled = ss[ply].eval + preFutilityValueMargin - moveCount * IncrementalFutilityMargin; + + if (futilityValueScaled < beta) + { + if (futilityValueScaled > bestValue) + bestValue = futilityValueScaled; + continue; + } } } @@ -1631,7 +1669,7 @@ namespace { && idle_thread_exists(threadID) && !AbortSearch && !thread_should_stop(threadID) - && split(pos, ss, ply, &beta, &beta, &bestValue, futilityValue, + && split(pos, ss, ply, &beta, &beta, &bestValue, futilityValue, //FIXME: SMP & futilityValue depth, &moveCount, &mp, threadID, false)) break; }