]> git.sesse.net Git - stockfish/blobdiff - src/uci.cpp
Revert previous patches due to bug
[stockfish] / src / uci.cpp
index 5a302a8d1b9d44286a39be48aeb25bcd69607ec0..e6f01d3c72670a24da0f7ed22c5c48651d264fec 100644 (file)
@@ -59,7 +59,7 @@ bool execute_uci_command(const string& cmd) {
   UCIParser up(cmd);
   string token;
 
-  up >> token; // operator>>() skips any whitespace
+  up >> skipws >> token;
 
   if (token == "quit")
       return false;
@@ -120,9 +120,10 @@ namespace {
 
   void set_position(Position& pos, UCIParser& up) {
 
+    Move m;
     string token, fen;
 
-    up >> token; // operator>>() skips any whitespace
+    up >> token;
 
     if (token == "startpos")
     {
@@ -139,8 +140,8 @@ namespace {
     else return;
 
     // Parse move list (if any)
-    while (up >> token)
-        pos.do_setup_move(move_from_uci(pos, token));
+    while (up >> token && (m = move_from_uci(pos, token)) != MOVE_NONE)
+        pos.do_setup_move(m);
   }
 
 
@@ -150,24 +151,20 @@ namespace {
 
   void set_option(UCIParser& up) {
 
-    string token, name;
-    string value = "true"; // UCI buttons don't have a "value" field
+    string token, name, value;
 
     up >> token; // Consume "name" token
-    up >> name;  // Read option name
 
-    // Handle names with included spaces
+    // Read option name (can contain spaces)
     while (up >> token && token != "value")
-        name += " " + token;
-
-    up >> value; // Read option value
+        name += string(" ", !name.empty()) + token;
 
-    // Handle values with included spaces
+    // Read option value (can contain spaces)
     while (up >> token)
-        value += " " + token;
+        value += string(" ", !value.empty()) + token;
 
     if (Options.find(name) != Options.end())
-        Options[name].set_value(value);
+        Options[name].set_value(value.empty() ? "true" : value); // UCI buttons don't have "value"
     else
         cout << "No such option: " << name << endl;
   }
@@ -182,8 +179,7 @@ namespace {
 
     string token;
     SearchLimits limits;
-    Move searchMoves[MAX_MOVES] = { MOVE_NONE };
-    Move* cur = searchMoves;
+    Move searchMoves[MAX_MOVES], *cur = searchMoves;
     int time[] = { 0, 0 }, inc[] = { 0, 0 };
 
     while (up >> token)
@@ -209,16 +205,11 @@ namespace {
         else if (token == "movetime")
             up >> limits.maxTime;
         else if (token == "searchmoves")
-        {
             while (up >> token)
                 *cur++ = move_from_uci(pos, token);
-
-            *cur = MOVE_NONE;
-        }
     }
 
-    assert(pos.is_ok());
-
+    *cur = MOVE_NONE;
     limits.time = time[pos.side_to_move()];
     limits.increment = inc[pos.side_to_move()];
 
@@ -228,7 +219,7 @@ namespace {
 
   // perft() is called when engine receives the "perft" command.
   // The function calls perft() passing the required search depth
-  // then prints counted nodes and elapsed time.
+  // then prints counted leaf nodes and elapsed time.
 
   void perft(Position& pos, UCIParser& up) {