X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fuci.cpp;h=7b7b116ee233999760f381c6e960b57a284739eb;hp=a10920a9714ab381a4a2d4b94fbdf51140b627b8;hb=18505f1fc40643ed033f681c36dc5efa3ddf2a05;hpb=7eb6a488ade31254151fd516aa4c94fc56b84a1f diff --git a/src/uci.cpp b/src/uci.cpp index a10920a9..7b7b116e 100644 --- a/src/uci.cpp +++ b/src/uci.cpp @@ -22,15 +22,15 @@ #include #include "evaluate.h" -#include "misc.h" #include "position.h" #include "search.h" #include "thread.h" +#include "tt.h" #include "ucioption.h" using namespace std; -extern void benchmark(istringstream& is); +extern void benchmark(const Position& pos, istream& is); namespace { @@ -45,7 +45,6 @@ namespace { void set_option(istringstream& up); void set_position(Position& pos, istringstream& up); void go(Position& pos, istringstream& up); - void perft(Position& pos, istringstream& up); } @@ -56,7 +55,7 @@ namespace { void uci_loop(const string& args) { - Position pos(StartFEN, false, 0); // The root position + Position pos(StartFEN, false, Threads.main_thread()); // The root position string cmd, token; while (token != "quit") @@ -87,7 +86,7 @@ void uci_loop(const string& args) { if (Search::Signals.stopOnPonderhit) { Search::Signals.stop = true; - Threads.wait_for_search_finished(); // Wake up if is sleeping + Threads.main_thread()->wake_up(); // Could be sleeping } } @@ -95,7 +94,7 @@ void uci_loop(const string& args) { go(pos, is); else if (token == "ucinewgame") - { /* Avoid returning "Unknown command" */ } + TT.clear(); else if (token == "isready") cout << "readyok" << endl; @@ -106,20 +105,17 @@ void uci_loop(const string& args) { else if (token == "setoption") set_option(is); - else if (token == "perft") - perft(pos, is); - else if (token == "d") pos.print(); else if (token == "flip") - pos.flip_me(); + pos.flip(); else if (token == "eval") cout << Eval::trace(pos) << endl; else if (token == "bench") - benchmark(is); + benchmark(pos, is); else if (token == "key") cout << "key: " << hex << pos.key() @@ -130,6 +126,17 @@ void uci_loop(const string& args) { cout << "id name " << engine_info(true) << "\n" << Options << "\nuciok" << endl; + + else if (token == "perft" && (is >> token)) // Read depth + { + stringstream ss; + + ss << Options["Hash"] << " " + << Options["Threads"] << " " << token << " current perft"; + + benchmark(pos, ss); + } + else cout << "Unknown command: " << cmd << endl; @@ -167,7 +174,7 @@ namespace { else return; - pos.from_fen(fen, Options["UCI_Chess960"]); + pos.from_fen(fen, Options["UCI_Chess960"], Threads.main_thread()); // Parse move list (if any) while (is >> token && (m = move_from_uci(pos, token)) != MOVE_NONE) @@ -244,27 +251,4 @@ namespace { Threads.start_searching(pos, limits, searchMoves); } - - - // perft() is called when engine receives the "perft" command. The function - // calls perft() with the required search depth then prints counted leaf nodes - // and elapsed time. - - void perft(Position& pos, istringstream& is) { - - int depth; - - if (!(is >> depth)) - return; - - Time time = Time::current_time(); - - int64_t n = Search::perft(pos, depth * ONE_PLY); - - int e = time.elapsed(); - - cout << "\nNodes " << n - << "\nTime (ms) " << e - << "\nNodes/second " << int(n / (e / 1000.0)) << endl; - } }