X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fsearch.cpp;h=2e8d5c6ff2ec3fbf530f78846822ad9805571eb6;hp=b4405fcf02845c2033f46aa60ab416d811e18136;hb=1d31065e1d1f04ecf47fc959523c560e8657fbfa;hpb=d06a8d0c188b796e115d503f85906fadb5625c70 diff --git a/src/search.cpp b/src/search.cpp index b4405fcf..2e8d5c6f 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -185,7 +185,7 @@ void Search::init() { } -/// Search::clear() resets search state to zero, to obtain reproducible results +/// Search::clear() resets search state to its initial value, to obtain reproducible results void Search::clear() { @@ -197,9 +197,10 @@ void Search::clear() { th->history.clear(); th->counterMoveHistory.clear(); th->resetCalls = true; + CounterMoveStats& cm = th->counterMoveHistory[NO_PIECE][0]; - int* t = &cm[NO_PIECE][0]; - std::fill(t, t + sizeof(cm), CounterMovePruneThreshold - 1); + auto* t = &cm[NO_PIECE][0]; + std::fill(t, t + sizeof(cm)/sizeof(*t), CounterMovePruneThreshold - 1); } Threads.main()->previousScore = VALUE_INFINITE; @@ -556,7 +557,7 @@ namespace { // Step 1. Initialize node Thread* thisThread = pos.this_thread(); inCheck = pos.checkers(); - moveCount = quietCount = ss->moveCount = 0; + moveCount = quietCount = ss->moveCount = 0; ss->history = 0; bestValue = -VALUE_INFINITE; ss->ply = (ss-1)->ply + 1; @@ -879,7 +880,7 @@ moves_loop: // When in check search starts from here // (alpha-s, beta-s), and just one fails high on (alpha, beta), then that move // is singular and should be extended. To verify this we do a reduced search // on all the other moves but the ttMove and if the result is lower than - // ttValue minus a margin then we extend the ttMove. + // ttValue minus a margin then we will extend the ttMove. if ( singularExtensionNode && move == ttMove && pos.legal(move)) @@ -895,7 +896,7 @@ moves_loop: // When in check search starts from here } else if ( givesCheck && !moveCountPruning - && pos.see_ge(move, VALUE_ZERO)) + && pos.see_ge(move)) extension = ONE_PLY; // Calculate new depth for this move @@ -979,8 +980,8 @@ moves_loop: // When in check search starts from here // Decrease reduction for moves that escape a capture. Filter out // castling moves, because they are coded as "king captures rook" and // hence break make_move(). - else if ( type_of(move) == NORMAL - && !pos.see_ge(make_move(to_sq(move), from_sq(move)), VALUE_ZERO)) + else if ( type_of(move) == NORMAL + && !pos.see_ge(make_move(to_sq(move), from_sq(move)))) r -= 2 * ONE_PLY; ss->history = cmh[moved_piece][to_sq(move)] @@ -1116,7 +1117,6 @@ moves_loop: // When in check search starts from here : inCheck ? mated_in(ss->ply) : DrawValue[pos.side_to_move()]; else if (bestMove) { - // Quiet best move: update move sorting heuristics if (!pos.capture_or_promotion(bestMove)) update_stats(pos, ss, bestMove, quietsSearched, quietCount, stat_bonus(depth)); @@ -1165,6 +1165,7 @@ moves_loop: // When in check search starts from here Value bestValue, value, ttValue, futilityValue, futilityBase, oldAlpha; bool ttHit, givesCheck, evasionPrunable; Depth ttDepth; + int moveCount; if (PvNode) { @@ -1175,6 +1176,7 @@ moves_loop: // When in check search starts from here ss->currentMove = bestMove = MOVE_NONE; ss->ply = (ss-1)->ply + 1; + moveCount = 0; // Check for an instant draw or if the maximum ply has been reached if (pos.is_draw(ss->ply) || ss->ply >= MAX_PLY) @@ -1258,6 +1260,8 @@ moves_loop: // When in check search starts from here ? pos.check_squares(type_of(pos.piece_on(from_sq(move)))) & to_sq(move) : pos.gives_check(move); + moveCount++; + // Futility pruning if ( !InCheck && !givesCheck @@ -1283,13 +1287,14 @@ moves_loop: // When in check search starts from here // Detect non-capture evasions that are candidates to be pruned evasionPrunable = InCheck + && (depth != DEPTH_ZERO || moveCount > 2) && bestValue > VALUE_MATED_IN_MAX_PLY && !pos.capture(move); // Don't search moves with negative SEE values if ( (!InCheck || evasionPrunable) && type_of(move) != PROMOTION - && !pos.see_ge(move, VALUE_ZERO)) + && !pos.see_ge(move)) continue; // Speculative prefetch as early as possible @@ -1297,7 +1302,10 @@ moves_loop: // When in check search starts from here // Check for legality just before making the move if (!pos.legal(move)) + { + moveCount--; continue; + } ss->currentMove = move; @@ -1504,7 +1512,7 @@ string UCI::pv(const Position& pos, Depth depth, Value alpha, Value beta) { for (size_t i = 0; i < multiPV; ++i) { - bool updated = (i <= PVIdx); + bool updated = (i <= PVIdx && rootMoves[i].score != -VALUE_INFINITE); if (depth == ONE_PLY && !updated) continue;