Move options into the engine

Move the engine options into the engine class, also avoid duplicated
initializations after startup.  UCIEngine needs to register an add_listener to
listen to all option changes and print these.  Also avoid a double
initialization of the TT, which was the case with the old state.

closes https://github.com/official-stockfish/Stockfish/pull/5356

No functional change
This commit is contained in:
Disservin
2024-06-04 22:29:27 +02:00
committed by Joost VandeVondele
parent c8213ba0d0
commit 7013a22b74
8 changed files with 183 additions and 116 deletions
+22 -6
View File
@@ -36,6 +36,8 @@ bool CaseInsensitiveLess::operator()(const std::string& s1, const std::string& s
[](char c1, char c2) { return std::tolower(c1) < std::tolower(c2); });
}
void OptionsMap::add_info_listener(InfoListener&& message_func) { info = std::move(message_func); }
void OptionsMap::setoption(std::istringstream& is) {
std::string token, name, value;
@@ -57,13 +59,20 @@ void OptionsMap::setoption(std::istringstream& is) {
Option OptionsMap::operator[](const std::string& name) const {
auto it = options_map.find(name);
return it != options_map.end() ? it->second : Option();
return it != options_map.end() ? it->second : Option(this);
}
Option& OptionsMap::operator[](const std::string& name) { return options_map[name]; }
Option& OptionsMap::operator[](const std::string& name) {
if (!options_map.count(name))
options_map[name] = Option(this);
return options_map[name];
}
std::size_t OptionsMap::count(const std::string& name) const { return options_map.count(name); }
Option::Option(const OptionsMap* map) :
parent(map) {}
Option::Option(const char* v, OnChange f) :
type("string"),
min(0),
@@ -127,10 +136,12 @@ void Option::operator<<(const Option& o) {
static size_t insert_order = 0;
*this = o;
idx = insert_order++;
}
auto p = this->parent;
*this = o;
this->parent = p;
idx = insert_order++;
}
// Updates currentValue and triggers on_change() action. It's up to
// the GUI to check for option's limits, but we could receive the new value
@@ -159,7 +170,12 @@ Option& Option::operator=(const std::string& v) {
currentValue = v;
if (on_change)
on_change(*this);
{
const auto ret = on_change(*this);
if (ret && parent != nullptr && parent->info != nullptr)
parent->info(ret);
}
return *this;
}