X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fsearch.cpp;h=9c7190bed0cacb99e7d813df7196e205cb23bac8;hp=4590bd4a1905c6f3e0baa5931f3284487565fe68;hb=946fa4762539307dcdcb30d08f13d627864e9bcf;hpb=df722521ba7027df394ed6370571cb5dc2ed6da1 diff --git a/src/search.cpp b/src/search.cpp index 4590bd4a..9c7190be 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -66,14 +66,14 @@ namespace { enum NodeType { Root, PV, NonPV }; // Razoring and futility margin based on depth - inline Value razor_margin(Depth d) { return Value(512 + 32 * d); } - inline Value futility_margin(Depth d) { return Value(200 * d); } + Value razor_margin(Depth d) { return Value(512 + 32 * d); } + Value futility_margin(Depth d) { return Value(200 * d); } // Futility and reductions lookup tables, initialized at startup int FutilityMoveCounts[2][16]; // [improving][depth] Depth Reductions[2][2][64][64]; // [pv][improving][depth][moveNumber] - template inline Depth reduction(bool i, Depth d, int mn) { + template Depth reduction(bool i, Depth d, int mn) { return Reductions[PvNode][i][std::min(d, 63 * ONE_PLY)][std::min(mn, 63)]; } @@ -129,7 +129,6 @@ namespace { }; size_t PVIdx; - TimeManagement Time; EasyMoveManager EasyMove; double BestMoveChanges; Value DrawValue[COLOR_NB]; @@ -218,11 +217,12 @@ template uint64_t Search::perft(Position& pos, Depth depth); void Search::think() { - Time.init(Limits, RootPos.side_to_move(), RootPos.game_ply(), now()); + Color us = RootPos.side_to_move(); + Time.init(Limits, us, RootPos.game_ply(), now()); int contempt = Options["Contempt"] * PawnValueEg / 100; // From centipawns - DrawValue[ RootPos.side_to_move()] = VALUE_DRAW - Value(contempt); - DrawValue[~RootPos.side_to_move()] = VALUE_DRAW + Value(contempt); + DrawValue[ us] = VALUE_DRAW - Value(contempt); + DrawValue[~us] = VALUE_DRAW + Value(contempt); TB::Hits = 0; TB::RootInTB = false; @@ -291,6 +291,11 @@ void Search::think() { Threads.timer->run = false; } + // When playing in 'nodes as time' mode, subtract the searched nodes from + // the available ones before to exit. + if (Limits.npmsec) + Time.availableNodes += Limits.inc[us] - RootPos.nodes_searched(); + // When we reach the maximum depth, we can arrive here without a raise of // Signals.stop. However, if we are pondering or in an infinite search, // the UCI protocol states that we shouldn't print the best move before the @@ -334,10 +339,6 @@ namespace { beta = VALUE_INFINITE; TT.new_search(); - History.clear(); - CounterMovesHistory.clear(); - Gains.clear(); - Countermoves.clear(); size_t multiPV = Options["MultiPV"]; Skill skill(Options["Skill Level"]); @@ -594,7 +595,7 @@ namespace { ss->currentMove = ttMove; // Can be MOVE_NONE // If ttMove is quiet, update killers, history, counter move on TT hit - if (ttValue >= beta && ttMove && !pos.capture_or_promotion(ttMove) && !inCheck) + if (ttValue >= beta && ttMove && !pos.capture_or_promotion(ttMove)) update_stats(pos, ss, ttMove, depth, nullptr, 0); return ttValue; @@ -940,8 +941,6 @@ moves_loop: // When in check and at SpNode search starts from here } ss->currentMove = move; - if (!SpNode && !captureOrPromotion && quietCount < 64) - quietsSearched[quietCount++] = move; // Step 14. Make the move pos.do_move(move, st, givesCheck); @@ -957,10 +956,9 @@ moves_loop: // When in check and at SpNode search starts from here ss->reduction = reduction(improving, depth, moveCount); if ( (!PvNode && cutNode) - || History[pos.piece_on(to_sq(move))][to_sq(move)] < VALUE_ZERO - || ( History[pos.piece_on(to_sq(move))][to_sq(move)] - + CounterMovesHistory[pos.piece_on(prevMoveSq)][prevMoveSq] - [pos.piece_on(to_sq(move))][to_sq(move)] < VALUE_ZERO)) + || ( History[pos.piece_on(to_sq(move))][to_sq(move)] < VALUE_ZERO + && CounterMovesHistory[pos.piece_on(prevMoveSq)][prevMoveSq] + [pos.piece_on(to_sq(move))][to_sq(move)] <= VALUE_ZERO)) ss->reduction += ONE_PLY; if (move == countermove) @@ -1096,6 +1094,9 @@ moves_loop: // When in check and at SpNode search starts from here } } + if (!SpNode && !captureOrPromotion && move != bestMove && quietCount < 64) + quietsSearched[quietCount++] = move; + // Step 19. Check for splitting the search if ( !SpNode && Threads.size() >= 2 @@ -1139,8 +1140,8 @@ moves_loop: // When in check and at SpNode search starts from here : inCheck ? mated_in(ss->ply) : DrawValue[pos.side_to_move()]; // Quiet best move: update killers, history and countermoves - else if (bestValue >= beta && !pos.capture_or_promotion(bestMove) && !inCheck) - update_stats(pos, ss, bestMove, depth, quietsSearched, quietCount - 1); + else if (bestMove && !pos.capture_or_promotion(bestMove)) + update_stats(pos, ss, bestMove, depth, quietsSearched, quietCount); tte->save(posKey, value_to_tt(bestValue, ss->ply), bestValue >= beta ? BOUND_LOWER : @@ -1297,8 +1298,7 @@ moves_loop: // When in check and at SpNode search starts from here // Detect non-capture evasions that are candidates to be pruned evasionPrunable = InCheck && bestValue > VALUE_MATED_IN_MAX_PLY - && !pos.capture(move) - && !pos.can_castle(pos.side_to_move()); + && !pos.capture(move); // Don't search moves with negative SEE values if ( (!InCheck || evasionPrunable) @@ -1398,10 +1398,12 @@ moves_loop: // When in check and at SpNode search starts from here *pv = MOVE_NONE; } - // update_stats() updates killers, history and countermoves stats after a fail-high - // of a quiet move. - void update_stats(const Position& pos, Stack* ss, Move move, Depth depth, Move* quiets, int quietsCnt) { + // update_stats() updates killers, history, countermove history and + // countermoves stats for a quiet best move. + + void update_stats(const Position& pos, Stack* ss, Move move, + Depth depth, Move* quiets, int quietsCnt) { if (ss->killers[0] != move) {