From b6dfd6bd54979b5ba96716c2b246d84e5fa5b9fb Mon Sep 17 00:00:00 2001 From: Disservin Date: Sat, 9 Mar 2024 12:14:57 +0100 Subject: [PATCH] Assorted cleanups - fix naming convention for `workingDirectory` - use type alias for `EvalFiles` everywhere - move `ponderMode` into `LimitsType` - move limits parsing into standalone static function closes https://github.com/official-stockfish/Stockfish/pull/5098 No functional change --- src/main.cpp | 3 +-- src/nnue/evaluate_nnue.cpp | 7 +++---- src/nnue/evaluate_nnue.h | 11 ++--------- src/search.h | 2 ++ src/thread.cpp | 5 ++--- src/thread.h | 3 +-- src/uci.cpp | 15 ++++++++++----- src/uci.h | 13 +++++-------- 8 files changed, 26 insertions(+), 33 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index de07d6a8..6ce656d7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,7 +17,6 @@ */ #include -#include #include "bitboard.h" #include "evaluate.h" @@ -40,7 +39,7 @@ int main(int argc, char* argv[]) { Tune::init(uci.options); - uci.evalFiles = Eval::NNUE::load_networks(uci.workingDirectory(), uci.options, uci.evalFiles); + uci.evalFiles = Eval::NNUE::load_networks(uci.working_directory(), uci.options, uci.evalFiles); uci.loop(); diff --git a/src/nnue/evaluate_nnue.cpp b/src/nnue/evaluate_nnue.cpp index efcf5b01..1efd83bf 100644 --- a/src/nnue/evaluate_nnue.cpp +++ b/src/nnue/evaluate_nnue.cpp @@ -30,7 +30,6 @@ #include #include #include -#include #include "../evaluate.h" #include "../misc.h" @@ -452,9 +451,9 @@ bool save_eval(std::ostream& stream, } // Save eval, to a file given by its name -bool save_eval(const std::optional& filename, - NetSize netSize, - const std::unordered_map& evalFiles) { +bool save_eval(const std::optional& filename, + NetSize netSize, + const EvalFiles& evalFiles) { std::string actualFilename; std::string msg; diff --git a/src/nnue/evaluate_nnue.h b/src/nnue/evaluate_nnue.h index c7b37860..febe8f9d 100644 --- a/src/nnue/evaluate_nnue.h +++ b/src/nnue/evaluate_nnue.h @@ -26,8 +26,8 @@ #include #include #include -#include +#include "../evaluate.h" #include "../misc.h" #include "../types.h" #include "nnue_architecture.h" @@ -35,11 +35,6 @@ namespace Stockfish { class Position; - -namespace Eval { -struct EvalFile; -} - } namespace Stockfish::Eval::NNUE { @@ -87,9 +82,7 @@ bool save_eval(std::ostream& stream, NetSize netSize, const std::string& name, const std::string& netDescription); -bool save_eval(const std::optional& filename, - NetSize netSize, - const std::unordered_map&); +bool save_eval(const std::optional& filename, NetSize netSize, const EvalFiles&); } // namespace Stockfish::Eval::NNUE diff --git a/src/search.h b/src/search.h index 4a1c68bb..bb9f63ff 100644 --- a/src/search.h +++ b/src/search.h @@ -109,6 +109,7 @@ struct LimitsType { time[WHITE] = time[BLACK] = inc[WHITE] = inc[BLACK] = npmsec = movetime = TimePoint(0); movestogo = depth = mate = perft = infinite = 0; nodes = 0; + ponderMode = false; } bool use_time_management() const { return time[WHITE] || time[BLACK]; } @@ -117,6 +118,7 @@ struct LimitsType { TimePoint time[COLOR_NB], inc[COLOR_NB], npmsec, movetime, startTime; int movestogo, depth, mate, perft, infinite; uint64_t nodes; + bool ponderMode; }; diff --git a/src/thread.cpp b/src/thread.cpp index 95646601..b62f5d8a 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -163,13 +163,12 @@ void ThreadPool::clear() { void ThreadPool::start_thinking(const OptionsMap& options, Position& pos, StateListPtr& states, - Search::LimitsType limits, - bool ponderMode) { + Search::LimitsType limits) { main_thread()->wait_for_search_finished(); main_manager()->stopOnPonderhit = stop = abortedSearch = false; - main_manager()->ponder = ponderMode; + main_manager()->ponder = limits.ponderMode; increaseDepth = true; diff --git a/src/thread.h b/src/thread.h index a2a1d18c..0d4c252c 100644 --- a/src/thread.h +++ b/src/thread.h @@ -79,8 +79,7 @@ class ThreadPool { } } - void - start_thinking(const OptionsMap&, Position&, StateListPtr&, Search::LimitsType, bool = false); + void start_thinking(const OptionsMap&, Position&, StateListPtr&, Search::LimitsType); void clear(); void set(Search::SharedState); diff --git a/src/uci.cpp b/src/uci.cpp index 4d4ea689..357369bf 100644 --- a/src/uci.cpp +++ b/src/uci.cpp @@ -175,11 +175,9 @@ void UCI::loop() { } while (token != "quit" && cli.argc == 1); // The command-line arguments are one-shot } -void UCI::go(Position& pos, std::istringstream& is, StateListPtr& states) { - +Search::LimitsType UCI::parse_limits(const Position& pos, std::istream& is) { Search::LimitsType limits; std::string token; - bool ponderMode = false; limits.startTime = now(); // The search starts as early as possible @@ -211,7 +209,14 @@ void UCI::go(Position& pos, std::istringstream& is, StateListPtr& states) { else if (token == "infinite") limits.infinite = 1; else if (token == "ponder") - ponderMode = true; + limits.ponderMode = true; + + return limits; +} + +void UCI::go(Position& pos, std::istringstream& is, StateListPtr& states) { + + Search::LimitsType limits = parse_limits(pos, is); Eval::NNUE::verify(options, evalFiles); @@ -221,7 +226,7 @@ void UCI::go(Position& pos, std::istringstream& is, StateListPtr& states) { return; } - threads.start_thinking(options, pos, states, limits, ponderMode); + threads.start_thinking(options, pos, states, limits); } void UCI::bench(Position& pos, std::istream& args, StateListPtr& states) { diff --git a/src/uci.h b/src/uci.h index 9d5f524a..f25bb8d5 100644 --- a/src/uci.h +++ b/src/uci.h @@ -21,7 +21,6 @@ #include #include -#include #include "evaluate.h" #include "misc.h" @@ -29,13 +28,10 @@ #include "thread.h" #include "tt.h" #include "ucioption.h" +#include "search.h" namespace Stockfish { -namespace Eval::NNUE { -enum NetSize : int; -} - class Move; enum Square : int; using Value = int; @@ -53,11 +49,12 @@ class UCI { static std::string wdl(Value v, int ply); static Move to_move(const Position& pos, std::string& str); - const std::string& workingDirectory() const { return cli.workingDirectory; } + static Search::LimitsType parse_limits(const Position& pos, std::istream& is); - OptionsMap options; + const std::string& working_directory() const { return cli.workingDirectory; } - std::unordered_map evalFiles; + OptionsMap options; + Eval::NNUE::EvalFiles evalFiles; private: TranspositionTable tt;