]> git.sesse.net Git - stockfish/blobdiff - src/uci.cpp
Don't update gamePly after each move
[stockfish] / src / uci.cpp
index 2dacd1c2f37b3b9a18a66c1d340d041342f4bb31..931891a0263cc6c32f7df193a8380a487e9aa905 100644 (file)
@@ -21,6 +21,7 @@
 #include <iostream>
 #include <sstream>
 #include <string>
+#include <vector>
 
 #include "evaluate.h"
 #include "misc.h"
@@ -36,6 +37,10 @@ namespace {
   // FEN string for the initial position
   const string StartPositionFEN = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
 
+  // Keep track of position keys along the setup moves (from start position to the
+  // position just before to start searching). This is needed by draw detection.
+  std::vector<StateInfo> SetupState(200, StateInfo());
+
   // UCIParser is a class for parsing UCI input. The class
   // is actually a string stream built on a given input string.
   typedef istringstream UCIParser;
@@ -59,7 +64,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 +125,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")
     {
@@ -138,9 +144,14 @@ namespace {
     }
     else return;
 
+    SetupState.clear();
+
     // 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)
+    {
+        SetupState.push_back(StateInfo());
+        pos.do_move(m, SetupState.back());
+    }
   }
 
 
@@ -150,24 +161,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,7 +189,7 @@ namespace {
 
     string token;
     SearchLimits limits;
-    Move searchMoves[MAX_MOVES], *cur = searchMoves;
+    std::vector<Move> searchMoves;
     int time[] = { 0, 0 }, inc[] = { 0, 0 };
 
     while (up >> token)
@@ -209,16 +216,14 @@ namespace {
             up >> limits.maxTime;
         else if (token == "searchmoves")
             while (up >> token)
-                *cur++ = move_from_uci(pos, token);
+                searchMoves.push_back(move_from_uci(pos, token));
     }
 
-    *cur = MOVE_NONE;
+    searchMoves.push_back(MOVE_NONE);
     limits.time = time[pos.side_to_move()];
     limits.increment = inc[pos.side_to_move()];
 
-    assert(pos.is_ok());
-
-    return think(pos, limits, searchMoves);
+    return think(pos, limits, &searchMoves[0]);
   }