X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fsearch.cpp;h=66bdb9b8b266b1c6c344cf3a92535037d5aa8f01;hp=16c46c9104fed8f75e10835959fd866a216c5cf7;hb=b58ecb85c73e31e3fec5d1ea983642864038a5b3;hpb=e1ed67aacbe7fb4b462b9141d3137bed0a3ea70b diff --git a/src/search.cpp b/src/search.cpp index 16c46c91..66bdb9b8 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -128,14 +128,7 @@ namespace { }; - /// Constants and variables initialized from UCI options - - // Minimum number of full depth (i.e. non-reduced) moves at PV and non-PV - // nodes - int LMRPVMoves, LMRNonPVMoves; - - // Depth limit for use of dynamic threat detection - Depth ThreatDepth; + /// Constants // Depth limit for selective search const Depth SelectiveDepth = 7*OnePly; @@ -174,25 +167,32 @@ namespace { const bool PruneDefendingMoves = false; const bool PruneBlockingMoves = false; - // Use futility pruning? - bool UseQSearchFutilityPruning, UseFutilityPruning; - // Margins for futility pruning in the quiescence search, and at frontier // and near frontier nodes const Value FutilityMarginQS = Value(0x80); - // Remaining depth: 1 ply 1.5 ply 2 ply 2.5 ply 3 ply 3.5 ply - const Value FutilityMargins[12] = { Value(0x100), Value(0x120), Value(0x200), Value(0x220), Value(0x250), Value(0x270), + // Remaining depth: 1 ply 1.5 ply 2 ply 2.5 ply 3 ply 3.5 ply + const Value FutilityMargins[12] = { Value(0x100), Value(0x120), Value(0x200), Value(0x220), Value(0x250), Value(0x270), // 4 ply 4.5 ply 5 ply 5.5 ply 6 ply 6.5 ply Value(0x2A0), Value(0x2C0), Value(0x340), Value(0x360), Value(0x3A0), Value(0x3C0) }; - // Razoring - const Depth RazorDepth = 4*OnePly; + // Razoring + const Depth RazorDepth = 4*OnePly; // Remaining depth: 1 ply 1.5 ply 2 ply 2.5 ply 3 ply 3.5 ply const Value RazorMargins[6] = { Value(0x180), Value(0x300), Value(0x300), Value(0x3C0), Value(0x3C0), Value(0x3C0) }; // Remaining depth: 1 ply 1.5 ply 2 ply 2.5 ply 3 ply 3.5 ply - const Value RazorApprMargins[6] = { Value(0x520), Value(0x300), Value(0x300), Value(0x300), Value(0x300), Value(0x300) }; + const Value RazorApprMargins[6] = { Value(0x520), Value(0x300), Value(0x300), Value(0x300), Value(0x300), Value(0x300) }; + + + /// Variables initialized from UCI options + + // Minimum number of full depth (i.e. non-reduced) moves at PV and non-PV + // nodes + int LMRPVMoves, LMRNonPVMoves; + + // Depth limit for use of dynamic threat detection + Depth ThreatDepth; // Last seconds noise filtering (LSN) bool UseLSNFiltering; @@ -207,15 +207,15 @@ namespace { // Search depth at iteration 1 const Depth InitialDepth = OnePly /*+ OnePly/2*/; - // Node counters + // Node counters, used only by thread[0] int NodesSincePoll; int NodesBetweenPolls = 30000; // Iteration counters int Iteration; - BetaCounterType BetaCounter; + BetaCounterType BetaCounter; // does not have internal data - // Scores and number of times the best move changed for each iteration: + // Scores and number of times the best move changed for each iteration IterationInfoType IterationInfo[PLY_MAX_PLUS_2]; int BestMoveChangesByIteration[PLY_MAX_PLUS_2]; @@ -281,10 +281,10 @@ namespace { bool move_is_killer(Move m, const SearchStack& ss); Depth extension(const Position &pos, Move m, bool pvNode, bool capture, bool check, bool singleReply, bool mateThreat, bool* dangerous); bool ok_to_do_nullmove(const Position &pos); - bool ok_to_prune(const Position &pos, Move m, Move threat, Depth d); + bool ok_to_prune(const Position &pos, Move m, Move threat, Depth d, const History& H); bool ok_to_use_TT(const TTEntry* tte, Depth depth, Value beta, int ply); bool ok_to_history(const Position &pos, Move m); - void update_history(const Position& pos, Move m, Depth depth, Move movesSearched[], int moveCount); + void update_history(const Position& pos, Move m, Depth depth, History& H, Move movesSearched[], int moveCount); void update_killers(Move m, SearchStack& ss); bool fail_high_ply_1(); @@ -330,8 +330,6 @@ int ActiveThreads = 1; // but it could turn out to be useful for debugging. Lock IOLock; -History H; // Should be made local? - // SearchStack::init() initializes a search stack. Used at the beginning of a // new search from the root. @@ -434,9 +432,6 @@ bool think(const Position &pos, bool infinite, bool ponder, int side_to_move, if (UseLogFile) LogFile.open(get_option_value_string("Search Log Filename").c_str(), std::ios::out | std::ios::app); - UseQSearchFutilityPruning = get_option_value_bool("Futility Pruning (Quiescence Search)"); - UseFutilityPruning = get_option_value_bool("Futility Pruning (Main Search)"); - UseLSNFiltering = get_option_value_bool("LSN filtering"); LSNTime = get_option_value_int("LSN Time Margin (sec)") * 1000; LSNValue = value_from_centipawns(get_option_value_int("LSN Value Margin")); @@ -644,7 +639,9 @@ namespace { // Initialize TT.new_search(); - H.clear(); + for (int i = 0; i < THREAD_MAX; i++) + Threads[i].H.clear(); + for (int i = 0; i < 3; i++) { ss[i].init(i); @@ -1056,7 +1053,7 @@ namespace { // Initialize a MovePicker object for the current position, and prepare // to search all moves - MovePicker mp = MovePicker(pos, true, ttMove, depth, &ss[ply]); + MovePicker mp = MovePicker(pos, true, ttMove, depth, Threads[threadID].H, &ss[ply]); Move move, movesSearched[256]; int moveCount = 0; @@ -1185,7 +1182,7 @@ namespace { Move m = ss[ply].pv[ply]; if (ok_to_history(pos, m)) // Only non capture moves are considered { - update_history(pos, m, depth, movesSearched, moveCount); + update_history(pos, m, depth, Threads[threadID].H, movesSearched, moveCount); update_killers(m, ss[ply]); } TT.store(pos.get_key(), value_to_tt(bestValue, ply), VALUE_TYPE_LOWER, depth, m); @@ -1317,15 +1314,14 @@ namespace { // Initialize a MovePicker object for the current position, and prepare // to search all moves: - MovePicker mp = MovePicker(pos, false, ttMove, depth, &ss[ply]); + MovePicker mp = MovePicker(pos, false, ttMove, depth, Threads[threadID].H, &ss[ply]); Move move, movesSearched[256]; int moveCount = 0; Value value, bestValue = -VALUE_INFINITE; Bitboard dcCandidates = mp.discovered_check_candidates(); Value futilityValue = VALUE_NONE; - bool useFutilityPruning = UseFutilityPruning - && depth < SelectiveDepth + bool useFutilityPruning = depth < SelectiveDepth && !isCheck; // Loop through all legal moves until no moves remain or a beta cutoff @@ -1355,7 +1351,7 @@ namespace { { // History pruning. See ok_to_prune() definition if ( moveCount >= 2 + int(depth) - && ok_to_prune(pos, move, ss[ply].threatMove, depth)) + && ok_to_prune(pos, move, ss[ply].threatMove, depth, Threads[threadID].H)) continue; // Value based pruning @@ -1445,7 +1441,7 @@ namespace { Move m = ss[ply].pv[ply]; if (ok_to_history(pos, m)) // Only non capture moves are considered { - update_history(pos, m, depth, movesSearched, moveCount); + update_history(pos, m, depth, Threads[threadID].H, movesSearched, moveCount); update_killers(m, ss[ply]); } TT.store(pos.get_key(), value_to_tt(bestValue, ply), VALUE_TYPE_LOWER, depth, m); @@ -1538,7 +1534,7 @@ namespace { // Initialize a MovePicker object for the current position, and prepare // to search the moves. Because the depth is <= 0 here, only captures, // queen promotions and checks (only if depth == 0) will be generated. - MovePicker mp = MovePicker(pos, pvNode, ttMove, depth); + MovePicker mp = MovePicker(pos, pvNode, ttMove, depth, Threads[threadID].H); Move move; int moveCount = 0; Bitboard dcCandidates = mp.discovered_check_candidates(); @@ -1556,8 +1552,7 @@ namespace { ss[ply].currentMove = move; // Futility pruning - if ( UseQSearchFutilityPruning - && enoughMaterial + if ( enoughMaterial && !isCheck && !pvNode && !move_promotion(move) @@ -1651,8 +1646,7 @@ namespace { Value value; Move move; bool isCheck = pos.is_check(); - bool useFutilityPruning = UseFutilityPruning - && sp->depth < SelectiveDepth + bool useFutilityPruning = sp->depth < SelectiveDepth && !isCheck; while ( sp->bestValue < sp->beta @@ -1681,7 +1675,7 @@ namespace { && !moveIsCapture && !move_promotion(move) && moveCount >= 2 + int(sp->depth) - && ok_to_prune(pos, move, ss[sp->ply].threatMove, sp->depth)) + && ok_to_prune(pos, move, ss[sp->ply].threatMove, sp->depth, Threads[threadID].H)) continue; // Make and search the move. @@ -2289,7 +2283,7 @@ namespace { // non-tactical moves late in the move list close to the leaves are // candidates for pruning. - bool ok_to_prune(const Position &pos, Move m, Move threat, Depth d) { + bool ok_to_prune(const Position &pos, Move m, Move threat, Depth d, const History& H) { Square mfrom, mto, tfrom, tto; assert(move_is_ok(m)); @@ -2368,7 +2362,7 @@ namespace { // update_history() registers a good move that produced a beta-cutoff // in history and marks as failures all the other moves of that ply. - void update_history(const Position& pos, Move m, Depth depth, + void update_history(const Position& pos, Move m, Depth depth, History& H, Move movesSearched[], int moveCount) { H.success(pos.piece_on(move_from(m)), move_to(m), depth);