X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fsearch.cpp;h=53a8bec9b15751981c22354e4a02525274c79887;hp=a73e1b80ff335183543a8ccd16acf6b14d8fdb82;hb=22ede4442cd285d7365b9497c3be65fb2c66b4be;hpb=191662a159c7a06f5a126f27fc9c99c69dad1fe8 diff --git a/src/search.cpp b/src/search.cpp index a73e1b80..53a8bec9 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -149,7 +149,7 @@ namespace { void set_non_pv_scores(const Position& pos); void sort() { insertion_sort(begin(), end()); } - void sort_multipv(int n) { insertion_sort(begin(), begin() + n); } + void sort_multipv(int n) { insertion_sort(begin(), begin() + n + 1); } }; @@ -424,7 +424,7 @@ bool think(Position& pos, bool infinite, bool ponder, int time[], int increment[ wait_for_stop_or_ponderhit(); cout << "bestmove " << bookMove << endl; - return true; + return !QuitRequest; } } @@ -484,7 +484,7 @@ bool think(Position& pos, bool infinite, bool ponder, int time[], int increment[ std::string name = Options["Search Log Filename"].value(); LogFile.open(name.c_str(), std::ios::out | std::ios::app); - LogFile << "Searching: " << pos.to_fen() + LogFile << "Searching: " << pos.to_fen(Options["UCI_Chess960"].value()) << "\ninfinite: " << infinite << " ponder: " << ponder << " time: " << myTime @@ -513,6 +513,9 @@ bool think(Position& pos, bool infinite, bool ponder, int time[], int increment[ << move_to_san(pos, ponderMove) // Works also with MOVE_NONE << endl; + // Return from think() with unchanged position + pos.undo_move(bestMove); + LogFile.close(); } @@ -567,7 +570,7 @@ namespace { Iteration = 1; // Send initial RootMoveList scoring (iteration 1) - cout << set960(pos.is_chess960()) // Is enough to set once at the beginning + cout << set960(Options["UCI_Chess960"].value()) // Is enough to set once at the beginning << "info depth " << Iteration << "\n" << rml[0].pv_info_to_uci(pos, alpha, beta) << endl; @@ -903,7 +906,7 @@ namespace { // Write PV lines to transposition table, in case the relevant entries // have been overwritten during the search. - for (int i = 0; i < MultiPV; i++) + for (int i = 0; i < Min(MultiPV, (int)rml.size()); i++) rml[i].insert_pv_in_tt(pos); return alpha; @@ -1927,12 +1930,21 @@ split_point_start: // At split points actual search starts from here } - // current_search_time() returns the number of milliseconds which have passed - // since the beginning of the current search. + // init_ss_array() does a fast reset of the first entries of a SearchStack + // array and of all the excludedMove and skipNullMove entries. - int current_search_time() { + void init_ss_array(SearchStack* ss, int size) { - return get_system_time() - SearchStartTime; + for (int i = 0; i < size; i++, ss++) + { + ss->excludedMove = MOVE_NONE; + ss->skipNullMove = false; + ss->reduction = DEPTH_ZERO; + ss->sp = NULL; + + if (i < 3) + ss->killers[0] = ss->killers[1] = ss->mateKiller = MOVE_NONE; + } } @@ -1955,7 +1967,17 @@ split_point_start: // At split points actual search starts from here return s.str(); } - // nps() computes the current nodes/second count. + + // current_search_time() returns the number of milliseconds which have passed + // since the beginning of the current search. + + int current_search_time() { + + return get_system_time() - SearchStartTime; + } + + + // nps() computes the current nodes/second count int nps(const Position& pos) { @@ -1973,13 +1995,6 @@ split_point_start: // At split points actual search starts from here static int lastInfoTime; int t = current_search_time(); - bool stillAtFirstMove = FirstRootMove - && !AspirationFailLow - && t > TimeMgr.available_time(); - - bool noMoreTime = t > TimeMgr.maximum_time() - || stillAtFirstMove; - // Poll for input if (data_available()) { @@ -2010,8 +2025,7 @@ split_point_start: // At split points actual search starts from here // should continue searching but switching from pondering to normal search. Pondering = false; - if ( Iteration >= 3 && UseTimeManagement - && (noMoreTime || StopOnPonderhit)) + if (StopOnPonderhit) StopRequest = true; } } @@ -2043,28 +2057,17 @@ split_point_start: // At split points actual search starts from here if (Pondering) return; - if ( (Iteration >= 3 && UseTimeManagement && noMoreTime) - || (ExactMaxTime && t >= ExactMaxTime) - || (Iteration >= 3 && MaxNodes && pos.nodes_searched() >= MaxNodes)) - StopRequest = true; - } - - - // init_ss_array() does a fast reset of the first entries of a SearchStack - // array and of all the excludedMove and skipNullMove entries. - - void init_ss_array(SearchStack* ss, int size) { + bool stillAtFirstMove = FirstRootMove + && !AspirationFailLow + && t > TimeMgr.available_time(); - for (int i = 0; i < size; i++, ss++) - { - ss->excludedMove = MOVE_NONE; - ss->skipNullMove = false; - ss->reduction = DEPTH_ZERO; - ss->sp = NULL; + bool noMoreTime = t > TimeMgr.maximum_time() + || stillAtFirstMove; - if (i < 3) - ss->killers[0] = ss->killers[1] = ss->mateKiller = MOVE_NONE; - } + if ( (UseTimeManagement && noMoreTime) + || (ExactMaxTime && t >= ExactMaxTime) + || (MaxNodes && pos.nodes_searched() >= MaxNodes)) // FIXME + StopRequest = true; } @@ -2073,7 +2076,7 @@ split_point_start: // At split points actual search starts from here // the UCI protocol: When pondering, the engine is not allowed to give a // "bestmove" before the GUI sends it a "stop" or "ponderhit" command. // We simply wait here until one of these commands is sent, and return, - // after which the bestmove and pondermove will be printed (in id_loop()). + // after which the bestmove and pondermove will be printed. void wait_for_stop_or_ponderhit() { @@ -2081,6 +2084,7 @@ split_point_start: // At split points actual search starts from here while (true) { + // Wait for a command from stdin if (!std::getline(std::cin, command)) command = "quit";