From c790307e4e02ee180f9762eb3a54fa8e5609d8f3 Mon Sep 17 00:00:00 2001 From: Fabian Fichter Date: Fri, 1 Apr 2022 17:44:49 +0200 Subject: [PATCH] Support checking of heredoc variant configs Analogous to the loading of variant configs, also support checking of configs specified directly in the CLI without an external file. --- src/uci.cpp | 34 ++++++++++++++++------------------ 1 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/uci.cpp b/src/uci.cpp index 2992100..9a87ab7 100644 --- a/src/uci.cpp +++ b/src/uci.cpp @@ -242,10 +242,10 @@ namespace { return int(0.5 + 1000 / (1 + std::exp((a - x) / b))); } - // load() is called when engine receives the "load" command. + // load() is called when engine receives the "load" or "check" command. // The function reads variant configuration files. - void load(istringstream& is) { + void load(istringstream& is, bool check = false) { string token; std::getline(is >> std::ws, token); @@ -262,30 +262,28 @@ namespace { std::string line; while (std::getline(cin, line) && line != token) ss << line << std::endl; - variants.parse_istream(ss); - Options["UCI_Variant"].set_combo(variants.get_keys()); + if (check) + variants.parse_istream(ss); + else + { + variants.parse_istream(ss); + Options["UCI_Variant"].set_combo(variants.get_keys()); + } } else { // store path if non-empty after trimming std::size_t end = token.find_last_not_of(' '); if (end != std::string::npos) - Options["VariantPath"] = token.erase(end + 1); + { + if (check) + variants.parse(token.erase(end + 1)); + else + Options["VariantPath"] = token.erase(end + 1); + } } } - // check() is called when engine receives the "check" command. - // The function reads a variant configuration file and validates it. - - void check(istringstream& is) { - - string token; - std::getline(is >> std::ws, token); - std::size_t end = token.find_last_not_of(' '); - if (end != std::string::npos) - variants.parse(token.erase(end + 1)); - } - } // namespace @@ -395,7 +393,7 @@ void UCI::loop(int argc, char* argv[]) { Eval::NNUE::save_eval(filename); } else if (token == "load") { load(is); argc = 1; } // continue reading stdin - else if (token == "check") check(is); + else if (token == "check") load(is, true); // UCI-Cyclone omits the "position" keyword else if (token == "fen" || token == "startpos") { -- 1.7.0.4