X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fthread.cpp;h=3f3f26cd63f4e6e6f354a1d26ff4fc25febc4640;hp=208cb0b1279d07f23f0b530c8b599b1444ab9bcb;hb=8a5a64eac563ff755048d40f6a5046ea4dcf0154;hpb=232c50fed0b80a0f39322a925575f760648ae0a5 diff --git a/src/thread.cpp b/src/thread.cpp index 208cb0b1..3f3f26cd 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -35,6 +35,7 @@ ThreadPool Threads; // Global object Thread::Thread(size_t n) : idx(n), stdThread(&Thread::idle_loop, this) { wait_for_search_finished(); + clear(); // Zero-init histories (based on std::array) } @@ -51,6 +52,21 @@ Thread::~Thread() { } +/// Thread::clear() reset histories, usually before a new game + +void Thread::clear() { + + counterMoves.fill(MOVE_NONE); + mainHistory.fill(0); + captureHistory.fill(0); + + for (auto& to : contHistory) + for (auto& h : to) + h.fill(0); + + contHistory[NO_PIECE][0].fill(Search::CounterMovePruneThreshold - 1); +} + /// Thread::start_searching() wakes up the thread that will start the search void Thread::start_searching() { @@ -96,7 +112,7 @@ void Thread::idle_loop() { /// ThreadPool::init() creates and launches the threads that will go -/// immediately to sleep in idle_loop. We cannot use the c'tor because +/// immediately to sleep in idle_loop. We cannot use the constructor because /// Threads is a static object and we need a fully initialized engine at /// this point due to allocation of Endgames in the Thread constructor.