]> git.sesse.net Git - stockfish/commitdiff
Restore deterministic search state
authorlucasart <lucas.braesch@gmail.com>
Wed, 6 May 2015 11:24:00 +0000 (19:24 +0800)
committerGary Linscott <glinscott@gmail.com>
Thu, 7 May 2015 21:20:32 +0000 (14:20 -0700)
Introduce helper function Search::reset() which clears all kind of search
memory, in order to restore a deterministic search state.

Generalize TT.clear() into Search::reset() for the following use cases:
- bench: needed to guarantee deterministic bench (ie. if you call bench from
interactive command line twice in a row you get the same value).
- Clear Hash: restore clean search state, which is the purpose of this button.
- ucinewgame: ditto.

No functional change.

Resolves #346

src/benchmark.cpp
src/movepick.h
src/search.cpp
src/search.h
src/uci.cpp
src/ucioption.cpp

index fbf7b0e3a88990004ecbbe5ec54a02ecb20c1290..07e1341ec354c77c2c973ef318a947012baa5064 100644 (file)
@@ -104,7 +104,7 @@ void benchmark(const Position& current, istream& is) {
 
   Options["Hash"]    = ttSize;
   Options["Threads"] = threads;
-  TT.clear();
+  Search::reset();
 
   if (limitType == "time")
       limits.movetime = stoi(limit); // movetime is in ms
index 423a6a1805e34a233844024940bd8d66839fb74b..44fc51f6263d73ca5a88919ff044e3e6b256cc12 100644 (file)
@@ -21,6 +21,7 @@
 #define MOVEPICK_H_INCLUDED
 
 #include <algorithm> // For std::max
+#include <cstring>   // For std::memset
 
 #include "movegen.h"
 #include "position.h"
@@ -43,6 +44,7 @@ struct Stats {
 
   const T* operator[](Piece pc) const { return table[pc]; }
   T* operator[](Piece pc) { return table[pc]; }
+  void clear() { std::memset(table, 0, sizeof(table)); }
 
   void update(Piece pc, Square to, Move m) {
 
index 9c7190bed0cacb99e7d813df7196e205cb23bac8..152e9fd68c4812854d0ce3d098581586fb56102f 100644 (file)
@@ -181,6 +181,18 @@ void Search::init() {
 }
 
 
+/// Search::reset() clears all search memory, to restore a deterministic state
+
+void Search::reset () {
+
+    TT.clear();
+    History.clear();
+    CounterMovesHistory.clear();
+    Gains.clear();
+    Countermoves.clear();
+}
+
+
 /// Search::perft() is our utility to verify move generation. All the leaf nodes
 /// up to the given depth are generated and counted and the sum returned.
 template<bool Root>
index 5e17b82928b60435fba05cff072d59fac72dc639..4e1d3c351ea51db7e887faff24d4c337e06c1919 100644 (file)
@@ -106,6 +106,7 @@ extern StateStackPtr SetupStates;
 
 void init();
 void think();
+void reset();
 template<bool Root> uint64_t perft(Position& pos, Depth depth);
 
 } // namespace Search
index a9fe4f207e856d715b0a6dc9bb23c7238c9cd28a..b8b371acfc036a4a08570773d058b28ef12173fe 100644 (file)
@@ -27,7 +27,6 @@
 #include "search.h"
 #include "thread.h"
 #include "timeman.h"
-#include "tt.h"
 #include "uci.h"
 
 using namespace std;
@@ -181,7 +180,7 @@ void UCI::loop(int argc, char* argv[]) {
 
       else if (token == "ucinewgame")
       {
-          TT.clear();
+          Search::reset();
           Time.availableNodes = 0;
       }
       else if (token == "isready")    sync_cout << "readyok" << sync_endl;
index 2906ae629d1e06cda2e0832272a25ffc2895a5bd..828d138fd212aa1a9e71c08f6b538127dafd7a10 100644 (file)
@@ -22,6 +22,7 @@
 #include <ostream>
 
 #include "misc.h"
+#include "search.h"
 #include "thread.h"
 #include "tt.h"
 #include "uci.h"
@@ -34,7 +35,7 @@ UCI::OptionsMap Options; // Global object
 namespace UCI {
 
 /// 'On change' actions, triggered by an option's value change
-void on_clear_hash(const Option&) { TT.clear(); }
+void on_clear_hash(const Option&) { Search::reset(); }
 void on_hash_size(const Option& o) { TT.resize(o); }
 void on_logger(const Option& o) { start_logger(o); }
 void on_threads(const Option&) { Threads.read_uci_options(); }