]> git.sesse.net Git - stockfish/blobdiff - src/uci.cpp
Fix startpos_ply_counter() regression
[stockfish] / src / uci.cpp
index e6f01d3c72670a24da0f7ed22c5c48651d264fec..4d68c86a04f3263216bfd764f6c4e3e535280e55 100644 (file)
@@ -21,6 +21,7 @@
 #include <iostream>
 #include <sstream>
 #include <string>
+#include <vector>
 
 #include "evaluate.h"
 #include "misc.h"
@@ -36,6 +37,11 @@ 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
+  // where, due to 50 moves rule, we need to check at most 100 plies back.
+  StateInfo StateRingBuf[102], *SetupState = StateRingBuf;
+
   // UCIParser is a class for parsing UCI input. The class
   // is actually a string stream built on a given input string.
   typedef istringstream UCIParser;
@@ -141,7 +147,13 @@ namespace {
 
     // Parse move list (if any)
     while (up >> token && (m = move_from_uci(pos, token)) != MOVE_NONE)
-        pos.do_setup_move(m);
+    {
+        pos.do_move(m, *SetupState);
+
+        // Increment pointer to StateRingBuf circular buffer
+        if (++SetupState - StateRingBuf >= 102)
+            SetupState = StateRingBuf;
+    }
   }
 
 
@@ -179,7 +191,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)
@@ -206,14 +218,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()];
 
-    return think(pos, limits, searchMoves);
+    return think(pos, limits, &searchMoves[0]);
   }