mirror of
https://github.com/sockspls/badfish
synced 2025-05-03 10:09:35 +00:00
Promote OptionsMap to a class
And add a bit of documentation too. No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
6056a43419
commit
786564068b
4 changed files with 74 additions and 69 deletions
|
@ -50,7 +50,6 @@ int main(int argc, char* argv[]) {
|
||||||
|
|
||||||
// Startup initializations
|
// Startup initializations
|
||||||
init_bitboards();
|
init_bitboards();
|
||||||
init_uci_options();
|
|
||||||
Position::init_zobrist();
|
Position::init_zobrist();
|
||||||
Position::init_piece_square_tables();
|
Position::init_piece_square_tables();
|
||||||
init_eval(1);
|
init_eval(1);
|
||||||
|
|
|
@ -78,7 +78,7 @@ bool execute_uci_command(const string& cmd) {
|
||||||
else if (token == "uci")
|
else if (token == "uci")
|
||||||
cout << "id name " << engine_name()
|
cout << "id name " << engine_name()
|
||||||
<< "\nid author " << engine_authors()
|
<< "\nid author " << engine_authors()
|
||||||
<< "\n" << options_to_uci()
|
<< "\n" << Options.print_all()
|
||||||
<< "\nuciok" << endl;
|
<< "\nuciok" << endl;
|
||||||
|
|
||||||
else if (token == "ucinewgame")
|
else if (token == "ucinewgame")
|
||||||
|
|
|
@ -60,53 +60,55 @@ static string stringify(const T& v) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// init_uci_options() initializes the UCI options to their hard coded default
|
/// OptionsMap c'tor initializes the UCI options to their hard coded default
|
||||||
/// values and initializes the default value of "Threads" and "Minimum Split Depth"
|
/// values and initializes the default value of "Threads" and "Minimum Split Depth"
|
||||||
/// parameters according to the number of CPU cores.
|
/// parameters according to the number of CPU cores.
|
||||||
|
|
||||||
void init_uci_options() {
|
OptionsMap::OptionsMap() {
|
||||||
|
|
||||||
Options["Use Search Log"] = Option(false);
|
OptionsMap& o = *this;
|
||||||
Options["Search Log Filename"] = Option("SearchLog.txt");
|
|
||||||
Options["Book File"] = Option("book.bin");
|
o["Use Search Log"] = Option(false);
|
||||||
Options["Best Book Move"] = Option(false);
|
o["Search Log Filename"] = Option("SearchLog.txt");
|
||||||
Options["Mobility (Middle Game)"] = Option(100, 0, 200);
|
o["Book File"] = Option("book.bin");
|
||||||
Options["Mobility (Endgame)"] = Option(100, 0, 200);
|
o["Best Book Move"] = Option(false);
|
||||||
Options["Pawn Structure (Middle Game)"] = Option(100, 0, 200);
|
o["Mobility (Middle Game)"] = Option(100, 0, 200);
|
||||||
Options["Pawn Structure (Endgame)"] = Option(100, 0, 200);
|
o["Mobility (Endgame)"] = Option(100, 0, 200);
|
||||||
Options["Passed Pawns (Middle Game)"] = Option(100, 0, 200);
|
o["Pawn Structure (Middle Game)"] = Option(100, 0, 200);
|
||||||
Options["Passed Pawns (Endgame)"] = Option(100, 0, 200);
|
o["Pawn Structure (Endgame)"] = Option(100, 0, 200);
|
||||||
Options["Space"] = Option(100, 0, 200);
|
o["Passed Pawns (Middle Game)"] = Option(100, 0, 200);
|
||||||
Options["Aggressiveness"] = Option(100, 0, 200);
|
o["Passed Pawns (Endgame)"] = Option(100, 0, 200);
|
||||||
Options["Cowardice"] = Option(100, 0, 200);
|
o["Space"] = Option(100, 0, 200);
|
||||||
Options["Check Extension (PV nodes)"] = Option(2, 0, 2);
|
o["Aggressiveness"] = Option(100, 0, 200);
|
||||||
Options["Check Extension (non-PV nodes)"] = Option(1, 0, 2);
|
o["Cowardice"] = Option(100, 0, 200);
|
||||||
Options["Pawn Push to 7th Extension (PV nodes)"] = Option(1, 0, 2);
|
o["Check Extension (PV nodes)"] = Option(2, 0, 2);
|
||||||
Options["Pawn Push to 7th Extension (non-PV nodes)"] = Option(1, 0, 2);
|
o["Check Extension (non-PV nodes)"] = Option(1, 0, 2);
|
||||||
Options["Passed Pawn Extension (PV nodes)"] = Option(1, 0, 2);
|
o["Pawn Push to 7th Extension (PV nodes)"] = Option(1, 0, 2);
|
||||||
Options["Passed Pawn Extension (non-PV nodes)"] = Option(0, 0, 2);
|
o["Pawn Push to 7th Extension (non-PV nodes)"] = Option(1, 0, 2);
|
||||||
Options["Pawn Endgame Extension (PV nodes)"] = Option(2, 0, 2);
|
o["Passed Pawn Extension (PV nodes)"] = Option(1, 0, 2);
|
||||||
Options["Pawn Endgame Extension (non-PV nodes)"] = Option(2, 0, 2);
|
o["Passed Pawn Extension (non-PV nodes)"] = Option(0, 0, 2);
|
||||||
Options["Minimum Split Depth"] = Option(4, 4, 7);
|
o["Pawn Endgame Extension (PV nodes)"] = Option(2, 0, 2);
|
||||||
Options["Maximum Number of Threads per Split Point"] = Option(5, 4, 8);
|
o["Pawn Endgame Extension (non-PV nodes)"] = Option(2, 0, 2);
|
||||||
Options["Threads"] = Option(1, 1, MAX_THREADS);
|
o["Minimum Split Depth"] = Option(4, 4, 7);
|
||||||
Options["Use Sleeping Threads"] = Option(true);
|
o["Maximum Number of Threads per Split Point"] = Option(5, 4, 8);
|
||||||
Options["Hash"] = Option(32, 4, 8192);
|
o["Threads"] = Option(1, 1, MAX_THREADS);
|
||||||
Options["Clear Hash"] = Option(false, "button");
|
o["Use Sleeping Threads"] = Option(true);
|
||||||
Options["Ponder"] = Option(true);
|
o["Hash"] = Option(32, 4, 8192);
|
||||||
Options["OwnBook"] = Option(true);
|
o["Clear Hash"] = Option(false, "button");
|
||||||
Options["MultiPV"] = Option(1, 1, 500);
|
o["Ponder"] = Option(true);
|
||||||
Options["Skill level"] = Option(20, 0, 20);
|
o["OwnBook"] = Option(true);
|
||||||
Options["Emergency Move Horizon"] = Option(40, 0, 50);
|
o["MultiPV"] = Option(1, 1, 500);
|
||||||
Options["Emergency Base Time"] = Option(200, 0, 30000);
|
o["Skill level"] = Option(20, 0, 20);
|
||||||
Options["Emergency Move Time"] = Option(70, 0, 5000);
|
o["Emergency Move Horizon"] = Option(40, 0, 50);
|
||||||
Options["Minimum Thinking Time"] = Option(20, 0, 5000);
|
o["Emergency Base Time"] = Option(200, 0, 30000);
|
||||||
Options["UCI_Chess960"] = Option(false);
|
o["Emergency Move Time"] = Option(70, 0, 5000);
|
||||||
Options["UCI_AnalyseMode"] = Option(false);
|
o["Minimum Thinking Time"] = Option(20, 0, 5000);
|
||||||
|
o["UCI_Chess960"] = Option(false);
|
||||||
|
o["UCI_AnalyseMode"] = Option(false);
|
||||||
|
|
||||||
// Set some SMP parameters accordingly to the detected CPU count
|
// Set some SMP parameters accordingly to the detected CPU count
|
||||||
Option& thr = Options["Threads"];
|
Option& thr = o["Threads"];
|
||||||
Option& msd = Options["Minimum Split Depth"];
|
Option& msd = o["Minimum Split Depth"];
|
||||||
|
|
||||||
thr.defaultValue = thr.currentValue = stringify(cpu_count());
|
thr.defaultValue = thr.currentValue = stringify(cpu_count());
|
||||||
|
|
||||||
|
@ -115,15 +117,15 @@ void init_uci_options() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// options_to_uci() returns a string with all the UCI options in chronological
|
/// OptionsMap::print_all() returns a string with all the UCI options in chronological
|
||||||
/// insertion order (the idx field) and in the format defined by the UCI protocol.
|
/// insertion order (the idx field) and in the format defined by the UCI protocol.
|
||||||
|
|
||||||
string options_to_uci() {
|
string OptionsMap::print_all() const {
|
||||||
|
|
||||||
std::stringstream s;
|
std::stringstream s;
|
||||||
|
|
||||||
for (size_t i = 0; i <= Options.size(); i++)
|
for (size_t i = 0; i <= size(); i++)
|
||||||
for (OptionsMap::const_iterator it = Options.begin(); it != Options.end(); ++it)
|
for (OptionsMap::const_iterator it = begin(); it != end(); ++it)
|
||||||
if (it->second.idx == i)
|
if (it->second.idx == i)
|
||||||
{
|
{
|
||||||
const Option& o = it->second;
|
const Option& o = it->second;
|
||||||
|
@ -143,13 +145,13 @@ string options_to_uci() {
|
||||||
|
|
||||||
/// Option class c'tors
|
/// Option class c'tors
|
||||||
|
|
||||||
Option::Option(const char* def) : type("string"), idx(Options.size()), minValue(0), maxValue(0)
|
Option::Option(const char* def) : type("string"), minValue(0), maxValue(0), idx(Options.size())
|
||||||
{ defaultValue = currentValue = def; }
|
{ defaultValue = currentValue = def; }
|
||||||
|
|
||||||
Option::Option(bool def, string t) : type(t), idx(Options.size()), minValue(0), maxValue(0)
|
Option::Option(bool def, string t) : type(t), minValue(0), maxValue(0), idx(Options.size())
|
||||||
{ defaultValue = currentValue = (def ? "true" : "false"); }
|
{ defaultValue = currentValue = (def ? "true" : "false"); }
|
||||||
|
|
||||||
Option::Option(int def, int minv, int maxv) : type("spin"), idx(Options.size()), minValue(minv), maxValue(maxv)
|
Option::Option(int def, int minv, int maxv) : type("spin"), minValue(minv), maxValue(maxv), idx(Options.size())
|
||||||
{ defaultValue = currentValue = stringify(def); }
|
{ defaultValue = currentValue = stringify(def); }
|
||||||
|
|
||||||
|
|
||||||
|
@ -164,8 +166,7 @@ void Option::set_value(const string& v) {
|
||||||
if (v.empty())
|
if (v.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ( (type == "check" || type == "button")
|
if ((type == "check" || type == "button") != (v == "true" || v == "false"))
|
||||||
!= (v == "true" || v == "false"))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (type == "spin")
|
if (type == "spin")
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
|
|
||||||
class Option {
|
class Option {
|
||||||
public:
|
public:
|
||||||
Option() {} // To allow insertion in a std::map
|
Option() {} // To be used in a std::map
|
||||||
Option(const char* defaultValue);
|
Option(const char* defaultValue);
|
||||||
Option(bool defaultValue, std::string type = "check");
|
Option(bool defaultValue, std::string type = "check");
|
||||||
Option(int defaultValue, int minValue, int maxValue);
|
Option(int defaultValue, int minValue, int maxValue);
|
||||||
|
@ -36,16 +36,33 @@ public:
|
||||||
template<typename T> T value() const;
|
template<typename T> T value() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend void init_uci_options();
|
friend class OptionsMap;
|
||||||
friend std::string options_to_uci();
|
|
||||||
|
|
||||||
std::string defaultValue, currentValue, type;
|
std::string defaultValue, currentValue, type;
|
||||||
size_t idx;
|
|
||||||
int minValue, maxValue;
|
int minValue, maxValue;
|
||||||
|
size_t idx;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/// Custom comparator because UCI options should not be case sensitive
|
||||||
|
struct CaseInsensitiveLess {
|
||||||
|
bool operator() (const std::string&, const std::string&) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/// Our options container is actually a map with a customized c'tor
|
||||||
|
class OptionsMap : public std::map<std::string, Option, CaseInsensitiveLess> {
|
||||||
|
public:
|
||||||
|
OptionsMap();
|
||||||
|
std::string print_all() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern OptionsMap Options;
|
||||||
|
|
||||||
|
|
||||||
|
/// Option::value() definition and specializations
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline T Option::value() const {
|
T Option::value() const {
|
||||||
|
|
||||||
assert(type == "spin");
|
assert(type == "spin");
|
||||||
return T(atoi(currentValue.c_str()));
|
return T(atoi(currentValue.c_str()));
|
||||||
|
@ -65,16 +82,4 @@ inline bool Option::value<bool>() const {
|
||||||
return currentValue == "true";
|
return currentValue == "true";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Custom comparator because UCI options should not be case sensitive
|
|
||||||
struct CaseInsensitiveLess {
|
|
||||||
bool operator() (const std::string&, const std::string&) const;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef std::map<std::string, Option, CaseInsensitiveLess> OptionsMap;
|
|
||||||
|
|
||||||
extern OptionsMap Options;
|
|
||||||
extern void init_uci_options();
|
|
||||||
extern std::string options_to_uci();
|
|
||||||
|
|
||||||
#endif // !defined(UCIOPTION_H_INCLUDED)
|
#endif // !defined(UCIOPTION_H_INCLUDED)
|
||||||
|
|
Loading…
Add table
Reference in a new issue