X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fsearch.cpp;h=0a53225abba9a81c8018edd10765b11c8dca00b9;hp=8e3e0dab0910e04a2470a300fb86fc4f703107c9;hb=6ae30e7cb10cf5b673aa6998d495b1527a43478d;hpb=9a595359628d82026513f7e978d40e944194b057 diff --git a/src/search.cpp b/src/search.cpp index 8e3e0dab..0a53225a 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -526,23 +526,36 @@ bool think(const Position& pos, bool infinite, bool ponder, int side_to_move, << " moves to go: " << movesToGo << std::endl; - // We're ready to start thinking. Call the iterative deepening loop function - // - // FIXME we really need to cleanup all this LSN ugliness - if (!loseOnTime) + // LSN filtering. Used only for developing purpose. Disabled by default. + if ( UseLSNFiltering + && loseOnTime) { - Value v = id_loop(pos, searchMoves); - loseOnTime = ( UseLSNFiltering - && myTime < LSNTime - && myIncrement == 0 - && v < -LSNValue); + // Step 2. If after last move we decided to lose on time, do it now! + while (SearchStartTime + myTime + 1000 > get_system_time()) + ; // wait here } - else + + // We're ready to start thinking. Call the iterative deepening loop function + Value v = id_loop(pos, searchMoves); + + // LSN filtering. Used only for developing purpose. Disabled by default. + if (UseLSNFiltering) { - loseOnTime = false; // reset for next match - while (SearchStartTime + myTime + 1000 > get_system_time()) - ; // wait here - id_loop(pos, searchMoves); // to fail gracefully + // Step 1. If this is sudden death game and our position is hopeless, + // decide to lose on time. + if ( !loseOnTime // If we already lost on time, go to step 3. + && myTime < LSNTime + && myIncrement == 0 + && movesToGo == 0 + && v < -LSNValue) + { + loseOnTime = true; + } + else if (loseOnTime) + { + // Step 3. Now after stepping over the time limit, reset flag for next match. + loseOnTime = false; + } } if (UseLogFile) @@ -1108,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); @@ -1145,7 +1165,7 @@ 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 + if ( depth >= 8 * OnePly && move == ttMove && ext < OnePly && is_lower_bound(tte->type()) @@ -1155,8 +1175,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. @@ -1448,7 +1467,7 @@ 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 + if ( depth >= 8 * OnePly && !excludedMove // do not allow recursive single-reply search && move == ttMove && ext < OnePly @@ -1459,13 +1478,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; } }