Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"allowEmpty" property for UCI options. Disallow empty values for net file. #3668

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/uci.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,16 @@ 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&);

std::string defaultValue, currentValue, type;
int min, max;
size_t idx;
OnChange on_change;
bool allowEmpty;
};

void init(OptionsMap&);
Expand Down
18 changes: 12 additions & 6 deletions src/ucioption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down Expand Up @@ -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 {
Expand All @@ -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

Expand All @@ -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;
Expand Down