Support checking of heredoc variant configs
authorFabian Fichter <ianfab@users.noreply.github.com>
Fri, 1 Apr 2022 15:44:49 +0000 (17:44 +0200)
committerFabian Fichter <ianfab@users.noreply.github.com>
Fri, 1 Apr 2022 15:44:49 +0000 (17:44 +0200)
Analogous to the loading of variant configs, also support checking
of configs specified directly in the CLI without an external file.

src/uci.cpp

index 2992100..9a87ab7 100644 (file)
@@ -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<false>(ss);
-        Options["UCI_Variant"].set_combo(variants.get_keys());
+        if (check)
+            variants.parse_istream<true>(ss);
+        else
+        {
+            variants.parse_istream<false>(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<true>(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<true>(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")
       {