]> git.sesse.net Git - stockfish/commitdiff
Execute an implied ucinewgame at startup
authorJoost VandeVondele <Joost.VandeVondele@gmail.com>
Sat, 6 May 2017 11:12:39 +0000 (13:12 +0200)
committerJoona Kiiski <joona@zoox.com>
Tue, 16 May 2017 01:54:13 +0000 (18:54 -0700)
execute an implied ucinewgame upon entering the UCI::loop,
to make sure that searches starting with and without an (optional) ucinewgame
command yield the same search.

This is needed now that seach::clear() initializes tables to non-zero default values.

No functional change

Closes #1101
Closes #1104

src/main.cpp
src/search.cpp
src/uci.cpp

index 83ec291fa653fa0e8090def1b479f950f9127637..063ce76e3503d8b6e27107444c7548fb69e8ce84 100644 (file)
@@ -24,7 +24,6 @@
 #include "position.h"
 #include "search.h"
 #include "thread.h"
-#include "tt.h"
 #include "uci.h"
 #include "syzygy/tbprobe.h"
 
@@ -44,8 +43,6 @@ int main(int argc, char* argv[]) {
   Search::init();
   Pawns::init();
   Threads.init();
-  Tablebases::init(Options["SyzygyPath"]);
-  TT.resize(Options["Hash"]);
 
   UCI::loop(argc, argv);
 
index fc877f3040d0923943a2a21c34f64af2a24b6bbc..e8e15ef2cf58826edff4c82b9a9d97ce948fe384 100644 (file)
@@ -185,7 +185,7 @@ void Search::init() {
 }
 
 
-/// Search::clear() resets search state to zero, to obtain reproducible results
+/// Search::clear() resets search state to its initial value, to obtain reproducible results
 
 void Search::clear() {
 
index 893c7e2f54827e1d43d56db13fb849bcb1b7e1f3..f3b5f54c60f0d9c0acbdbc2358008146f339afe4 100644 (file)
@@ -28,6 +28,7 @@
 #include "position.h"
 #include "search.h"
 #include "thread.h"
+#include "tt.h"
 #include "timeman.h"
 #include "uci.h"
 #include "syzygy/tbprobe.h"
@@ -137,6 +138,15 @@ namespace {
     Threads.start_thinking(pos, States, limits);
   }
 
+  // On ucinewgame following steps are needed to reset the state
+  void newgame() {
+
+    TT.resize(Options["Hash"]);
+    Search::clear();
+    Tablebases::init(Options["SyzygyPath"]);
+    Time.availableNodes = 0;
+  }
+
 } // namespace
 
 
@@ -151,6 +161,8 @@ void UCI::loop(int argc, char* argv[]) {
   Position pos;
   string token, cmd;
 
+  newgame(); // Implied ucinewgame before the first position command
+
   pos.set(StartFEN, false, &States->back(), Threads.main());
 
   for (int i = 1; i < argc; ++i)
@@ -185,12 +197,7 @@ void UCI::loop(int argc, char* argv[]) {
                     << "\n"       << Options
                     << "\nuciok"  << sync_endl;
 
-      else if (token == "ucinewgame")
-      {
-          Search::clear();
-          Tablebases::init(Options["SyzygyPath"]);
-          Time.availableNodes = 0;
-      }
+      else if (token == "ucinewgame") newgame();
       else if (token == "isready")    sync_cout << "readyok" << sync_endl;
       else if (token == "go")         go(pos, is);
       else if (token == "position")   position(pos, is);