From 9d080df742491afe280c0f90e8a6141cf8aca834 Mon Sep 17 00:00:00 2001 From: Tomasz Sobczyk Date: Fri, 20 Aug 2021 18:45:16 +0200 Subject: [PATCH] Allow each UCI option to control individually whether empty values are possible. Disallow empty values for net file. --- src/uci.h | 3 +++ src/ucioption.cpp | 18 ++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/uci.h b/src/uci.h index d3160109d6e..a987dce0f6e 100644 --- a/src/uci.h +++ b/src/uci.h @@ -58,6 +58,8 @@ class Option { operator std::string() const; bool operator==(const char*) const; + void set_allow_empty(bool v); + private: friend std::ostream& operator<<(std::ostream&, const OptionsMap&); @@ -65,6 +67,7 @@ class Option { int min, max; size_t idx; OnChange on_change; + bool allowEmpty; }; void init(OptionsMap&); diff --git a/src/ucioption.cpp b/src/ucioption.cpp index 0cafd3e92d0..0390b0ddcfe 100644 --- a/src/ucioption.cpp +++ b/src/ucioption.cpp @@ -81,6 +81,8 @@ void init(OptionsMap& o) { o["SyzygyProbeLimit"] << Option(7, 0, 7); o["Use NNUE"] << Option(true, on_use_NNUE); o["EvalFile"] << Option(EvalFileDefaultName, on_eval_file); + + o["EvalFile"].set_allow_empty(false); } @@ -113,19 +115,19 @@ std::ostream& operator<<(std::ostream& os, const OptionsMap& om) { /// Option class constructors and conversion operators -Option::Option(const char* v, OnChange f) : type("string"), min(0), max(0), on_change(f) +Option::Option(const char* v, OnChange f) : type("string"), min(0), max(0), on_change(f), allowEmpty(true) { defaultValue = currentValue = v; } -Option::Option(bool v, OnChange f) : type("check"), min(0), max(0), on_change(f) +Option::Option(bool v, OnChange f) : type("check"), min(0), max(0), on_change(f), allowEmpty(false) { defaultValue = currentValue = (v ? "true" : "false"); } -Option::Option(OnChange f) : type("button"), min(0), max(0), on_change(f) +Option::Option(OnChange f) : type("button"), min(0), max(0), on_change(f), allowEmpty(true) {} -Option::Option(double v, int minv, int maxv, OnChange f) : type("spin"), min(minv), max(maxv), on_change(f) +Option::Option(double v, int minv, int maxv, OnChange f) : type("spin"), min(minv), max(maxv), on_change(f), allowEmpty(false) { defaultValue = currentValue = std::to_string(v); } -Option::Option(const char* v, const char* cur, OnChange f) : type("combo"), min(0), max(0), on_change(f) +Option::Option(const char* v, const char* cur, OnChange f) : type("combo"), min(0), max(0), on_change(f), allowEmpty(false) { defaultValue = v; currentValue = cur; } Option::operator double() const { @@ -144,6 +146,10 @@ bool Option::operator==(const char* s) const { && !CaseInsensitiveLess()(s, currentValue); } +void Option::set_allow_empty(bool v) { + allowEmpty = v; +} + /// operator<<() inits options and assigns idx in the correct printing order @@ -164,7 +170,7 @@ Option& Option::operator=(const string& v) { assert(!type.empty()); - if ( (type != "button" && type != "string" && v.empty()) + if ( (!allowEmpty && v.empty()) || (type == "check" && v != "true" && v != "false") || (type == "spin" && (stof(v) < min || stof(v) > max))) return *this;