From 18860cce406f9646cb6af218c2b23f51d2e47b8d Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Thu, 18 Sep 2008 10:32:12 +0100 Subject: [PATCH] Improve time managment If we need some more and we are in time advantage take it. Signed-off-by: Marco Costalba --- src/benchmark.cpp | 3 ++- src/search.cpp | 26 ++++++++++++++++---------- src/uci.cpp | 1 - 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/benchmark.cpp b/src/benchmark.cpp index 4c6c0da6..7e2628b1 100644 --- a/src/benchmark.cpp +++ b/src/benchmark.cpp @@ -123,7 +123,8 @@ void benchmark(const std::string& commandLine) { for (it = positions.begin(); it != positions.end(); ++it) { Move moves[1] = {MOVE_NONE}; + int dummy[2] = {0, 0}; Position pos(*it); - think(pos, true, false, 0, 0, 0, 0, 0, 0, secsPerPos * 1000, moves); + think(pos, true, false, 0, dummy, dummy, 0, 0, 0, secsPerPos * 1000, moves); } } diff --git a/src/search.cpp b/src/search.cpp index 5599faab..c05bbd4c 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -181,7 +181,7 @@ namespace { // Time managment variables int SearchStartTime; int MaxNodes, MaxDepth; - int MaxSearchTime, AbsoluteMaxSearchTime, ExtraSearchTime; + int MaxSearchTime, AbsoluteMaxSearchTime, ExtraSearchTime, TimeAdvantage; Move BestRootMove, PonderMove, EasyMove; int RootMoveNumber; bool InfiniteSearch; @@ -407,14 +407,6 @@ void think(const Position &pos, bool infinite, bool ponder, int side_to_move, init_eval(ActiveThreads); } - // Write information to search log file: - if(UseLogFile) { - LogFile << "Searching: " << pos.to_fen() << '\n'; - LogFile << "infinite: " << infinite << " ponder: " << ponder - << " time: " << time << " increment: " << increment - << " moves to go: " << movesToGo << '\n'; - } - // Wake up sleeping threads: wake_sleeping_threads(); @@ -425,7 +417,8 @@ void think(const Position &pos, bool infinite, bool ponder, int side_to_move, int myTime = time[side_to_move]; int myIncrement = increment[side_to_move]; int oppTime = time[1 - side_to_move]; - int oppIncrement = increment[1 - side_to_move]; + + TimeAdvantage = myTime - oppTime; if(!movesToGo) { // Sudden death time control if(increment) { @@ -465,6 +458,15 @@ void think(const Position &pos, bool infinite, bool ponder, int side_to_move, else NodesBetweenPolls = 30000; + + // Write information to search log file: + if(UseLogFile) { + LogFile << "Searching: " << pos.to_fen() << '\n'; + LogFile << "infinite: " << infinite << " ponder: " << ponder + << " time: " << myTime << " increment: " << myIncrement + << " moves to go: " << movesToGo << '\n'; + } + // We're ready to start thinking. Call the iterative deepening loop // function: id_loop(pos, searchMoves); @@ -640,6 +642,10 @@ namespace { BestMoveChangesByIteration[Iteration] * (MaxSearchTime / 2) + BestMoveChangesByIteration[Iteration-1] * (MaxSearchTime / 3); + // If we need some more and we are in time advantage take it. + if (ExtraSearchTime > 0 && TimeAdvantage > 2 * MaxSearchTime) + ExtraSearchTime += MaxSearchTime / 2; + // Stop search if most of MaxSearchTime is consumed at the end of the // iteration. We probably don't have enough time to search the first // move at the next iteration anyway. diff --git a/src/uci.cpp b/src/uci.cpp index 1a2c05a4..6862a5e8 100644 --- a/src/uci.cpp +++ b/src/uci.cpp @@ -134,7 +134,6 @@ namespace { TT.clear(); Position::init_piece_square_tables(); RootPosition.from_fen(StartPosition); - } else if (token == "isready") std::cout << "readyok" << std::endl; -- 2.39.2