X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fsearch.cpp;h=c574058df4be545a297dc83f74da0c43203c4ecb;hp=3ba0dbc905b9f6a75c4da3be45dca9b23a2d17f2;hb=900e2d4e1e1424076ec197cbe22e941fbf8cbf6b;hpb=3cf6471738dc704ddf553d5f8d2dc9875c2ccbe7 diff --git a/src/search.cpp b/src/search.cpp index 3ba0dbc9..c574058d 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -194,7 +194,7 @@ void Search::think() { goto finalize; } - if (Options["OwnBook"] && !Limits.infinite) + if (Options["OwnBook"] && !Limits.infinite && !Limits.mate) { Move bookMove = book.probe(RootPos, Options["Book File"], Options["Best Book Move"]); @@ -410,6 +410,12 @@ namespace { if (depth > 2 && BestMoveChanges) bestMoveNeverChanged = false; + // Do we have found a "mate in x"? + if ( Limits.mate + && bestValue >= VALUE_MATE_IN_MAX_PLY + && VALUE_MATE - bestValue <= 2 * Limits.mate) + Signals.stop = true; + // Do we have time for the next iteration? Can we stop searching now? if (Limits.use_time_management() && !Signals.stopOnPonderhit) { @@ -578,15 +584,9 @@ namespace { else if (tte) { - // Following asserts are valid only in single thread condition because - // TT access is always racy and its contents cannot be trusted. - assert(tte->static_value() != VALUE_NONE || Threads.size() > 1); - assert(ttValue != VALUE_NONE || tte->type() == BOUND_NONE || Threads.size() > 1); - - ss->staticEval = eval = tte->static_value(); - ss->evalMargin = tte->static_value_margin(); - - if (eval == VALUE_NONE || ss->evalMargin == VALUE_NONE) // Due to a race + // Never assume anything on values stored in TT + if ( (ss->staticEval = eval = tte->static_value()) == VALUE_NONE + ||(ss->evalMargin = tte->static_value_margin()) == VALUE_NONE) eval = ss->staticEval = evaluate(pos, ss->evalMargin); // Can ttValue be used as a better position evaluation? @@ -602,6 +602,11 @@ namespace { ss->staticEval, ss->evalMargin); } + // Handling of UCI command 'mate in x moves'. We simply return if after + // 'x' moves we still have not checkmated the opponent. + if (PvNode && !RootNode && !inCheck && Limits.mate && ss->ply > 2 * Limits.mate) + return eval; + // Update gain for the parent non-capture move given the static position // evaluation before and after the move. if ( (move = (ss-1)->currentMove) != MOVE_NULL @@ -1164,12 +1169,9 @@ split_point_start: // At split points actual search starts from here } else if (tte) { - assert(tte->static_value() != VALUE_NONE || Threads.size() > 1); - - ss->staticEval = bestValue = tte->static_value(); - ss->evalMargin = tte->static_value_margin(); - - if (ss->staticEval == VALUE_NONE || ss->evalMargin == VALUE_NONE) // Due to a race + // Never assume anything on values stored in TT + if ( (ss->staticEval = bestValue = tte->static_value()) == VALUE_NONE + ||(ss->evalMargin = tte->static_value_margin()) == VALUE_NONE) ss->staticEval = bestValue = evaluate(pos, ss->evalMargin); } else