From 2931463d3a8b2ea86ac223842dc775fb0ab68de6 Mon Sep 17 00:00:00 2001 From: Joost VandeVondele Date: Sun, 20 Sep 2020 19:43:38 +0200 Subject: [PATCH] Revert earlier TB changes. they were not correct. Unfortunately, also restores the race on RootInTB --- src/learn/learn.cpp | 3 --- src/learn/multi_think.cpp | 3 --- src/search.cpp | 36 +++++++++++------------------------- src/search.h | 12 ------------ src/syzygy/tbprobe.h | 2 ++ src/thread.cpp | 2 -- src/thread.h | 1 - 7 files changed, 13 insertions(+), 46 deletions(-) diff --git a/src/learn/learn.cpp b/src/learn/learn.cpp index c1900af3..ba904e9d 100644 --- a/src/learn/learn.cpp +++ b/src/learn/learn.cpp @@ -1985,9 +1985,6 @@ namespace Learner Threads.main()->ponder = false; - // init global vars - Tablebases::init(); - // About Search::Limits // Be careful because this member variable is global and affects other threads. { diff --git a/src/learn/multi_think.cpp b/src/learn/multi_think.cpp index 22e49e81..7c389d40 100644 --- a/src/learn/multi_think.cpp +++ b/src/learn/multi_think.cpp @@ -24,9 +24,6 @@ void MultiThink::go_think() // Call the derived class's init(). init(); - // init global vars - Tablebases::init(); - // About Search::Limits // Be careful because this member variable is global and affects other threads. { diff --git a/src/search.cpp b/src/search.cpp index 9f5119a2..e1616c5c 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -43,24 +43,9 @@ namespace Search { namespace Tablebases { int Cardinality; + bool RootInTB; bool UseRule50; Depth ProbeDepth; - - void init() { - - UseRule50 = bool(Options["Syzygy50MoveRule"]); - ProbeDepth = int(Options["SyzygyProbeDepth"]); - Cardinality = int(Options["SyzygyProbeLimit"]); - - // Tables with fewer pieces than SyzygyProbeLimit are searched with - // ProbeDepth == DEPTH_ZERO - if (Cardinality > MaxCardinality) - { - Cardinality = MaxCardinality; - ProbeDepth = 0; - } - } - } namespace TB = Tablebases; @@ -1859,7 +1844,7 @@ string UCI::pv(const Position& pos, Depth depth, Value alpha, Value beta) { size_t pvIdx = pos.this_thread()->pvIdx; size_t multiPV = std::min((size_t)Options["MultiPV"], rootMoves.size()); uint64_t nodesSearched = Threads.nodes_searched(); - uint64_t tbHits = Threads.tb_hits() + (pos.this_thread()->rootInTB ? rootMoves.size() : 0); + uint64_t tbHits = Threads.tb_hits() + (TB::RootInTB ? rootMoves.size() : 0); for (size_t i = 0; i < multiPV; ++i) { @@ -1871,7 +1856,7 @@ string UCI::pv(const Position& pos, Depth depth, Value alpha, Value beta) { Depth d = updated ? depth : depth - 1; Value v = updated ? rootMoves[i].score : rootMoves[i].previousScore; - bool tb = pos.this_thread()->rootInTB && abs(v) < VALUE_MATE_IN_MAX_PLY; + bool tb = TB::RootInTB && abs(v) < VALUE_MATE_IN_MAX_PLY; v = tb ? rootMoves[i].tbScore : v; if (ss.rdbuf()->in_avail()) // Not at first line @@ -1938,8 +1923,10 @@ bool RootMove::extract_ponder_from_tt(Position& pos) { void Tablebases::rank_root_moves(Position& pos, Search::RootMoves& rootMoves) { - auto& rootInTB = pos.this_thread()->rootInTB; - rootInTB = false; + RootInTB = false; + UseRule50 = bool(Options["Syzygy50MoveRule"]); + ProbeDepth = int(Options["SyzygyProbeDepth"]); + Cardinality = int(Options["SyzygyProbeLimit"]); bool dtz_available = true; // Tables with fewer pieces than SyzygyProbeLimit are searched with @@ -1953,17 +1940,17 @@ void Tablebases::rank_root_moves(Position& pos, Search::RootMoves& rootMoves) { if (Cardinality >= popcount(pos.pieces()) && !pos.can_castle(ANY_CASTLING)) { // Rank moves using DTZ tables - rootInTB = root_probe(pos, rootMoves); + RootInTB = root_probe(pos, rootMoves); - if (!rootInTB) + if (!RootInTB) { // DTZ tables are missing; try to rank moves using WDL tables dtz_available = false; - rootInTB = root_probe_wdl(pos, rootMoves); + RootInTB = root_probe_wdl(pos, rootMoves); } } - if (rootInTB) + if (RootInTB) { // Sort moves according to TB rank std::sort(rootMoves.begin(), rootMoves.end(), @@ -1979,7 +1966,6 @@ void Tablebases::rank_root_moves(Position& pos, Search::RootMoves& rootMoves) { for (auto& m : rootMoves) m.tbRank = 0; } - } // --- expose the functions such as fixed depth search used for learning to the outside diff --git a/src/search.h b/src/search.h index fd5814ef..20dfe909 100644 --- a/src/search.h +++ b/src/search.h @@ -24,7 +24,6 @@ #include "misc.h" #include "movepick.h" #include "types.h" -#include "uci.h" class Position; @@ -111,17 +110,6 @@ void clear(); } // namespace Search -namespace Tablebases { - -extern int MaxCardinality; -extern int Cardinality; -extern bool UseRule50; -extern Depth ProbeDepth; - -void init(); - -} - namespace Learner { // A pair of reader and evaluation value. Returned by Learner::search(),Learner::qsearch(). diff --git a/src/syzygy/tbprobe.h b/src/syzygy/tbprobe.h index 6af5d278..b998989b 100644 --- a/src/syzygy/tbprobe.h +++ b/src/syzygy/tbprobe.h @@ -43,6 +43,8 @@ enum ProbeState { ZEROING_BEST_MOVE = 2 // Best move zeroes DTZ (capture or pawn move) }; +extern int MaxCardinality; + void init(const std::string& paths); WDLScore probe_wdl(Position& pos, ProbeState* result); int probe_dtz(Position& pos, ProbeState* result); diff --git a/src/thread.cpp b/src/thread.cpp index ef4cb398..1aa66a81 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -192,8 +192,6 @@ void ThreadPool::start_thinking(Position& pos, StateListPtr& states, || std::count(limits.searchmoves.begin(), limits.searchmoves.end(), m)) rootMoves.emplace_back(m); - Tablebases::init(); - if (!rootMoves.empty()) Tablebases::rank_root_moves(pos, rootMoves); diff --git a/src/thread.h b/src/thread.h index e0c838c8..042bc2e9 100644 --- a/src/thread.h +++ b/src/thread.h @@ -74,7 +74,6 @@ public: CapturePieceToHistory captureHistory; ContinuationHistory continuationHistory[2][2]; Score contempt; - bool rootInTB; };