From fb50e16cdda68e05d08ed3992a04e5a396a461e3 Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Wed, 3 Nov 2010 09:32:14 +0100 Subject: [PATCH] Retire push_button() and button_was_pressed() Directly access the underlying bool option. No functional change. Signed-off-by: Marco Costalba --- src/search.cpp | 5 ++++- src/uci.cpp | 30 ++++++++++++++++-------------- src/ucioption.cpp | 25 +------------------------ src/ucioption.h | 3 --- 4 files changed, 21 insertions(+), 42 deletions(-) diff --git a/src/search.cpp b/src/search.cpp index 9649c2da..c5c8b839 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -425,8 +425,11 @@ bool think(Position& pos, bool infinite, bool ponder, int time[], int increment[ // Read UCI option values TT.set_size(get_option_value_int("Hash")); - if (button_was_pressed("Clear Hash")) + if (get_option_value_bool("Clear Hash")) + { + set_option_value("Clear Hash", "false"); TT.clear(); + } CheckExtension[1] = Depth(get_option_value_int("Check Extension (PV nodes)")); CheckExtension[0] = Depth(get_option_value_int("Check Extension (non-PV nodes)")); diff --git a/src/uci.cpp b/src/uci.cpp index e59df6dd..c9ecbf23 100644 --- a/src/uci.cpp +++ b/src/uci.cpp @@ -122,7 +122,7 @@ namespace { } else if (token == "ucinewgame") { - push_button("New Game"); + set_option_value("New Game", "true"); pos.from_fen(StartPositionFEN); } else if (token == "isready") @@ -227,20 +227,22 @@ namespace { if (!(uip >> token)) // operator>>() skips any whitespace return; - if (token == "name" && uip >> name) - { - while (uip >> token && token != "value") - name += (" " + token); + if (token != "name" || !(uip >> name)) + return; - if (token == "value" && uip >> value) - { - while (uip >> token) - value += (" " + token); + while (uip >> token && token != "value") + name += (" " + token); - set_option_value(name, value); - } else - push_button(name); + if (token != "value" || !(uip >> value)) + { + set_option_value(name, "true"); + return; } + + while (uip >> token) + value += (" " + token); + + set_option_value(name, value); } @@ -260,7 +262,7 @@ namespace { int time[2] = {0, 0}, inc[2] = {0, 0}; int movesToGo = 0, depth = 0, nodes = 0, moveTime = 0; bool infinite = false, ponder = false; - Move searchMoves[500]; + Move searchMoves[MOVES_MAX]; searchMoves[0] = MOVE_NONE; @@ -317,6 +319,6 @@ namespace { tm = get_system_time() - tm; std::cout << "\nNodes " << n << "\nTime (ms) " << tm - << "\nNodes/second " << (int)(n/(tm/1000.0)) << std::endl; + << "\nNodes/second " << int(n / (tm / 1000.0)) << std::endl; } } diff --git a/src/ucioption.cpp b/src/ucioption.cpp index e1b5ae55..2db1beeb 100644 --- a/src/ucioption.cpp +++ b/src/ucioption.cpp @@ -286,7 +286,7 @@ void set_option_value(const string& name, const string& value) { if (opt.type == CHECK && v != "0" && v != "1") return; - else if (opt.type == SPIN) + if (opt.type == SPIN) { int val = atoi(v.c_str()); if (val < opt.minValue || val > opt.maxValue) @@ -294,26 +294,3 @@ void set_option_value(const string& name, const string& value) { } opt.currentValue = v; } - - -/// push_button() is used to tell the engine that a UCI parameter of type -/// "button" has been selected: - -void push_button(const string& buttonName) { - - set_option_value(buttonName, "true"); -} - - -/// button_was_pressed() tests whether a UCI parameter of type "button" has -/// been selected since the last time the function was called, in this case -/// it also resets the button. - -bool button_was_pressed(const string& buttonName) { - - if (!get_option_value(buttonName)) - return false; - - set_option_value(buttonName, "false"); - return true; -} diff --git a/src/ucioption.h b/src/ucioption.h index b5648af5..e68e438b 100644 --- a/src/ucioption.h +++ b/src/ucioption.h @@ -36,9 +36,6 @@ extern void print_uci_options(); extern bool get_option_value_bool(const std::string& optionName); extern int get_option_value_int(const std::string& optionName); extern std::string get_option_value_string(const std::string& optionName); -extern bool button_was_pressed(const std::string& buttonName); extern void set_option_value(const std::string& optionName,const std::string& newValue); -extern void push_button(const std::string& buttonName); - #endif // !defined(UCIOPTION_H_INCLUDED) -- 2.39.2