X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fsearch.cpp;h=7eb04308b4c3bbd6c72247a6d920927ffc91b9e5;hb=5bec768d42fc8ce34b4dc0574ef9f4e61bfd8853;hp=0d5362e7fcbde939760f55dd856c2a8ab913e165;hpb=850c021f868653d9ed51cd0ef5f2a50004d986bd;p=stockfish diff --git a/src/search.cpp b/src/search.cpp index 0d5362e7..7eb04308 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -1121,7 +1121,14 @@ namespace { return alpha; // Transposition table lookup. At PV nodes, we don't use the TT for - // pruning, but only for move ordering. + // pruning, but only for move ordering. This is to avoid problems in + // the following areas: + // + // * Repetition draw detection + // * Fifty move rule detection + // * Searching for a mate + // * Printing of full PV line + // tte = TT.retrieve(pos.get_key()); ttMove = (tte ? tte->move() : MOVE_NONE); @@ -1130,6 +1137,11 @@ namespace { { search_pv(pos, ss, alpha, beta, depth-2*OnePly, ply, threadID); ttMove = ss[ply].pv[ply]; + tte = TT.retrieve(pos.get_key()); + + // Following assert could fail, for instance when we have + // moveCount == 0 we return without saving a TT entry. + /* assert(tte); */ } // Initialize a MovePicker object for the current position, and prepare @@ -1158,8 +1170,11 @@ namespace { // To verify this we do a reduced search on all the other moves but the ttMove, // if result is lower then TT value minus a margin then we assume ttMove is the // only one playable. It is a kind of relaxed single reply extension. - if ( depth >= 4 * OnePly - && move == ttMove + // Note that could be ttMove != tte->move() due to IID, so we always use tte->move() + // to avoid aliases when we probe tte->depth() and tte->type() + if ( depth >= 8 * OnePly + && tte + && move == tte->move() && ext < OnePly && is_lower_bound(tte->type()) && tte->depth() >= depth - 3 * OnePly) @@ -1168,8 +1183,7 @@ namespace { if (abs(ttValue) < VALUE_KNOWN_WIN) { - Depth d = Max(Min(depth / 2, depth - 4 * OnePly), OnePly); - Value excValue = search(pos, ss, ttValue - SingleReplyMargin, d, ply, false, threadID, ttMove); + Value excValue = search(pos, ss, ttValue - SingleReplyMargin, depth / 2, ply, false, threadID, ttMove); // If search result is well below the foreseen score of the ttMove then we // assume ttMove is the only one realistically playable and we extend it. @@ -1424,6 +1438,7 @@ namespace { { search(pos, ss, beta, Min(depth/2, depth-2*OnePly), ply, false, threadID); ttMove = ss[ply].pv[ply]; + tte = TT.retrieve(pos.get_key()); } // Initialize a MovePicker object for the current position, and prepare @@ -1461,9 +1476,12 @@ namespace { // To verify this we do a reduced search on all the other moves but the ttMove, // if result is lower then TT value minus a margin then we assume ttMove is the // only one playable. It is a kind of relaxed single reply extension. - if ( depth >= 4 * OnePly - && !excludedMove // do not allow recursive single-reply search - && move == ttMove + // Note that could be ttMove != tte->move() due to IID, so we always use tte->move() + // to avoid aliases when we probe tte->depth() and tte->type() + if ( depth >= 8 * OnePly + && tte + && move == tte->move() + && !excludedMove // Do not allow recursive single-reply search && ext < OnePly && is_lower_bound(tte->type()) && tte->depth() >= depth - 3 * OnePly) @@ -1472,13 +1490,12 @@ namespace { if (abs(ttValue) < VALUE_KNOWN_WIN) { - Depth d = Max(Min(depth / 2, depth - 4 * OnePly), OnePly); - Value excValue = search(pos, ss, ttValue - SingleReplyMargin, d, ply, false, threadID, ttMove); + Value excValue = search(pos, ss, ttValue - SingleReplyMargin, depth / 2, ply, false, threadID, ttMove); // If search result is well below the foreseen score of the ttMove then we // assume ttMove is the only one realistically playable and we extend it. if (excValue < ttValue - SingleReplyMargin) - ext = (depth >= 8 * OnePly) ? OnePly : ext + OnePly / 2; + ext = OnePly; } }