]> git.sesse.net Git - stockfish/blobdiff - src/uci.cpp
Clear transposition table on "ucinewgame"
[stockfish] / src / uci.cpp
index 126cd5c4c1e8a027e40a29573b3794495b4695af..7b7b116ee233999760f381c6e960b57a284739eb 100644 (file)
 #include <string>
 
 #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);
 }
 
 
@@ -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,9 +105,6 @@ 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();
 
@@ -119,7 +115,7 @@ void uci_loop(const string& args) {
           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;
 
@@ -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;
-  }
 }