From 5fa28b12fa4dcece84db555ca19d15308b2f1e1a Mon Sep 17 00:00:00 2001 From: Tomasz Sobczyk Date: Wed, 7 Oct 2020 11:20:53 +0200 Subject: [PATCH] Allow setting UCI options programmatically. --- src/uci.cpp | 19 ++++++++++++------- src/uci.h | 1 + 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/uci.cpp b/src/uci.cpp index a123bbc0..166e437c 100644 --- a/src/uci.cpp +++ b/src/uci.cpp @@ -109,7 +109,7 @@ namespace { // setoption() is called when engine receives the "setoption" UCI command. The // function updates the UCI option ("name") to the given value ("value"). - void setoption(istringstream& is) { + void setoption_from_stream(istringstream& is) { string token, name, value; @@ -123,10 +123,7 @@ namespace { while (is >> token) value += (value.empty() ? "" : " ") + token; - if (Options.count(name)) - Options[name] = value; - else - sync_cout << "No such option: " << name << sync_endl; + UCI::setoption(name, value); } @@ -195,7 +192,7 @@ namespace { else trace_eval(pos); } - else if (token == "setoption") setoption(is); + else if (token == "setoption") setoption_from_stream(is); else if (token == "position") position(pos, is, states); else if (token == "ucinewgame") { Search::clear(); elapsed = now(); } // Search::clear() may take some while } @@ -212,6 +209,14 @@ namespace { } // namespace +void UCI::setoption(const std::string& name, const std::string& value) +{ + if (Options.count(name)) + Options[name] = value; + else + sync_cout << "No such option: " << name << sync_endl; +} + // The win rate model returns the probability (per mille) of winning given an eval // and a game-ply. The model fits rather accurately the LTC fishtest statistics. int UCI::win_rate_model(Value v, int ply) { @@ -318,7 +323,7 @@ void UCI::loop(int argc, char* argv[]) { << "\n" << Options << "\nuciok" << sync_endl; - else if (token == "setoption") setoption(is); + else if (token == "setoption") setoption_from_stream(is); else if (token == "go") go(pos, is, states); else if (token == "position") position(pos, is, states); else if (token == "ucinewgame") Search::clear(); diff --git a/src/uci.h b/src/uci.h index 2e0f5c11..192963cb 100644 --- a/src/uci.h +++ b/src/uci.h @@ -75,6 +75,7 @@ std::string wdl(Value v, int ply); int win_rate_model(Value v, int ply); double win_rate_model_double(double v, int ply); Move to_move(const Position& pos, std::string& str); +void setoption(const std::string& name, const std::string& value); } // namespace UCI