]> git.sesse.net Git - stockfish/blobdiff - src/ucioption.cpp
Fix regression: engine hangs while pondering
[stockfish] / src / ucioption.cpp
index 8031ff15d855bf233ec3f54055268a6f9ffad440..9e718c02c89ca8a5670b555ed05ccca93fb9026a 100644 (file)
@@ -17,6 +17,7 @@
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
+#include <algorithm>
 #include <cctype>
 #include <iostream>
 #include <sstream>
@@ -33,26 +34,15 @@ OptionsMap Options; // Global object
 
 
 // Our case insensitive less() function as required by UCI protocol
-bool CaseInsensitiveLess::operator() (const string& s1, const string& s2) const {
-
-  int c1, c2;
-  size_t i = 0;
-
-  while (i < s1.size() && i < s2.size())
-  {
-      c1 = tolower(s1[i]);
-      c2 = tolower(s2[i++]);
+static bool ci_less(char c1, char c2) { return tolower(c1) < tolower(c2); }
 
-      if (c1 != c2)
-          return c1 < c2;
-  }
-  return s1.size() < s2.size();
+bool CaseInsensitiveLess::operator() (const string& s1, const string& s2) const {
+  return std::lexicographical_compare(s1.begin(), s1.end(), s2.begin(), s2.end(), ci_less);
 }
 
 
-// stringify() converts a numeric value of type T to a std::string
-template<typename T>
-static string stringify(const T& v) {
+// An helper to convert an integer value to a std::string
+static string int_to_string(int v) {
 
   std::ostringstream ss;
   ss << v;
@@ -74,8 +64,6 @@ OptionsMap::OptionsMap() {
   o["Best Book Move"] = UCIOption(false);
   o["Mobility (Middle Game)"] = UCIOption(100, 0, 200);
   o["Mobility (Endgame)"] = UCIOption(100, 0, 200);
-  o["Pawn Structure (Middle Game)"] = UCIOption(100, 0, 200);
-  o["Pawn Structure (Endgame)"] = UCIOption(100, 0, 200);
   o["Passed Pawns (Middle Game)"] = UCIOption(100, 0, 200);
   o["Passed Pawns (Endgame)"] = UCIOption(100, 0, 200);
   o["Space"] = UCIOption(100, 0, 200);
@@ -90,7 +78,7 @@ OptionsMap::OptionsMap() {
   o["Ponder"] = UCIOption(true);
   o["OwnBook"] = UCIOption(true);
   o["MultiPV"] = UCIOption(1, 1, 500);
-  o["Skill level"] = UCIOption(20, 0, 20);
+  o["Skill Level"] = UCIOption(20, 0, 20);
   o["Emergency Move Horizon"] = UCIOption(40, 0, 50);
   o["Emergency Base Time"] = UCIOption(200, 0, 30000);
   o["Emergency Move Time"] = UCIOption(70, 0, 5000);
@@ -102,10 +90,10 @@ OptionsMap::OptionsMap() {
   UCIOption& thr = o["Threads"];
   UCIOption& msd = o["Minimum Split Depth"];
 
-  thr.defaultValue = thr.currentValue = stringify(cpu_count());
+  thr.defaultValue = thr.currentValue = int_to_string(cpu_count());
 
   if (cpu_count() >= 8)
-      msd.defaultValue = msd.currentValue = stringify(7);
+      msd.defaultValue = msd.currentValue = int_to_string(7);
 }
 
 
@@ -144,7 +132,7 @@ UCIOption::UCIOption(bool def, string t) : type(t), minValue(0), maxValue(0), id
 { defaultValue = currentValue = (def ? "true" : "false"); }
 
 UCIOption::UCIOption(int def, int minv, int maxv) : type("spin"), minValue(minv), maxValue(maxv), idx(Options.size())
-{ defaultValue = currentValue = stringify(def); }
+{ defaultValue = currentValue = int_to_string(def); }
 
 
 /// set_value() updates currentValue of the Option object. Normally it's up to