X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fsearch.cpp;h=24ae2f631227ee0c412a31e21c44a8151dd74f26;hp=8e3e0dab0910e04a2470a300fb86fc4f703107c9;hb=cd0c7373cdc95acd7b4096860df21826eb7faace;hpb=9a595359628d82026513f7e978d40e944194b057;ds=sidebyside diff --git a/src/search.cpp b/src/search.cpp index 8e3e0dab..24ae2f63 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -526,23 +526,41 @@ 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) { - 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! + if ( loseOnTime + && myTime < LSNTime // double check: catches some very rear false positives! + && myIncrement == 0 + && movesToGo == 0) + { + while (SearchStartTime + myTime + 1000 > get_system_time()) + ; // wait here + } else if (loseOnTime) // false positive, reset flag + loseOnTime = false; } - 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)