diff --git a/src/search.cpp b/src/search.cpp index 9924b0cec..f5133905e 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -480,7 +480,6 @@ void Search::Worker::iterative_deepening() { double fallingEval = (11.85 + 2.24 * (mainThread->bestPreviousAverageScore - bestValue) + 0.93 * (mainThread->iterValue[iterIdx] - bestValue)) / 100.0; - fallingEval = std::clamp(fallingEval, 0.57, 1.70); // If the bestMove is stable over several iterations, reduce time accordingly @@ -717,7 +716,6 @@ Value Search::Worker::search( update_quiet_histories(pos, ss, *this, ttData.move, std::min(132 * depth - 72, 985)); - // Extra penalty for early quiet moves of the previous ply if (prevSq != SQ_NONE && (ss - 1)->moveCount < 4 && !priorCapture) update_continuation_histories(ss - 1, pos.piece_on(prevSq), prevSq, -2060); @@ -738,6 +736,7 @@ Value Search::Worker::search( // Check that the ttValue after the tt move would also trigger a cutoff if (!is_valid(ttDataNext.value)) return ttData.value; + if ((ttData.value >= beta) == (-ttDataNext.value >= beta)) return ttData.value; } @@ -858,6 +857,7 @@ Value Search::Worker::search( // Hindsight adjustment of reductions based on static evaluation difference. if (priorReduction >= 3 && !opponentWorsening) depth++; + if (priorReduction >= 2 && depth >= 2 && ss->staticEval + (ss - 1)->staticEval > 169) depth--; @@ -919,7 +919,6 @@ Value Search::Worker::search( } } - improving |= ss->staticEval >= beta; // Step 10. Internal iterative reductions @@ -1187,7 +1186,6 @@ moves_loop: // When in check, search starts here if (ss->ttPv) r -= 2719 + PvNode * 983 + (ttData.value > alpha) * 922 + (ttData.depth >= depth) * (934 + cutNode * 1011); - // These reduction adjustments have no proven non-linear scaling r += 714; // Base reduction offset to compensate for other tweaks r -= moveCount * 73; @@ -1220,7 +1218,6 @@ moves_loop: // When in check, search starts here // Decrease/increase reduction for moves with a good/bad history r -= ss->statScore * 850 / 8192; - // Step 17. Late moves reduction / extension (LMR) if (depth >= 2 && moveCount > 1) { @@ -1265,6 +1262,7 @@ moves_loop: // When in check, search starts here value = -search(pos, ss + 1, -(alpha + 1), -alpha, newDepth - (r > 3957) - (r > 5654 && newDepth > 2), !cutNode); } + // For PV nodes only, do a full PV search on the first move or after a fail high, // otherwise let the parent node fail low with value <= alpha and try another move. if (PvNode && (moveCount == 1 || value > alpha)) @@ -1445,7 +1443,6 @@ moves_loop: // When in check, search starts here captureHistory[pos.piece_on(prevSq)][prevSq][type_of(capturedPiece)] << 1012; } - if (PvNode) bestValue = std::min(bestValue, maxValue); @@ -1560,8 +1557,10 @@ Value Search::Worker::qsearch(Position& pos, Stack* ss, Value alpha, Value beta) { // Never assume anything about values stored in TT unadjustedStaticEval = ttData.eval; + if (!is_valid(unadjustedStaticEval)) unadjustedStaticEval = evaluate(pos); + ss->staticEval = bestValue = to_corrected_static_eval(unadjustedStaticEval, correctionValue); @@ -1573,8 +1572,7 @@ Value Search::Worker::qsearch(Position& pos, Stack* ss, Value alpha, Value beta) else { unadjustedStaticEval = evaluate(pos); - - ss->staticEval = bestValue = + ss->staticEval = bestValue = to_corrected_static_eval(unadjustedStaticEval, correctionValue); } @@ -1583,6 +1581,7 @@ Value Search::Worker::qsearch(Position& pos, Stack* ss, Value alpha, Value beta) { if (!is_decisive(bestValue)) bestValue = (bestValue + beta) / 2; + if (!ss->ttHit) ttWriter.write(posKey, value_to_tt(bestValue, ss->ply), false, BOUND_LOWER, DEPTH_UNSEARCHED, Move::none(), unadjustedStaticEval, @@ -1596,7 +1595,6 @@ Value Search::Worker::qsearch(Position& pos, Stack* ss, Value alpha, Value beta) futilityBase = ss->staticEval + 351; } - const PieceToHistory* contHist[] = {(ss - 1)->continuationHistory}; Square prevSq = ((ss - 1)->currentMove).is_ok() ? ((ss - 1)->currentMove).to_sq() : SQ_NONE; @@ -1699,7 +1697,6 @@ Value Search::Worker::qsearch(Position& pos, Stack* ss, Value alpha, Value beta) if (!is_decisive(bestValue) && bestValue > beta) bestValue = (bestValue + beta) / 2; - Color us = pos.side_to_move(); if (!ss->inCheck && !moveCount && !pos.non_pawn_material(us) && type_of(pos.captured_piece()) >= ROOK) @@ -1731,7 +1728,6 @@ Depth Search::Worker::reduction(bool i, Depth d, int mn, int delta) const { return reductionScale - delta * 608 / rootDelta + !i * reductionScale * 238 / 512 + 1182; } - // elapsed() returns the time elapsed since the search started. If the // 'nodestime' option is enabled, it will return the count of nodes searched // instead. This function is called to check whether the search should be @@ -1869,6 +1865,7 @@ void update_continuation_histories(Stack* ss, Piece pc, Square to, int bonus) { // Only update the first 2 continuation histories if we are in check if (ss->inCheck && i > 2) break; + if (((ss - i)->currentMove).is_ok()) (*(ss - i)->continuationHistory)[pc][to] << (bonus * weight / 1024) + 88 * (i < 2); } @@ -1925,7 +1922,6 @@ Move Skill::pick_best(const RootMoves& rootMoves, size_t multiPV) { return best; } - // Used to print debug info and, more importantly, to detect // when we are out of available time and thus stop the search. void SearchManager::check_time(Search::Worker& worker) {