From 7edd1f7ccd500ad3fb6959ca18415ed4b8808313 Mon Sep 17 00:00:00 2001 From: Joost VandeVondele Date: Sat, 6 May 2017 13:12:39 +0200 Subject: [PATCH] Execute an implied ucinewgame at startup 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 | 3 --- src/search.cpp | 2 +- src/uci.cpp | 19 +++++++++++++------ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 83ec291f..063ce76e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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); diff --git a/src/search.cpp b/src/search.cpp index fc877f30..e8e15ef2 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -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() { diff --git a/src/uci.cpp b/src/uci.cpp index 893c7e2f..f3b5f54c 100644 --- a/src/uci.cpp +++ b/src/uci.cpp @@ -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); -- 2.39.2