]> git.sesse.net Git - stockfish/blobdiff - src/uci.cpp
Be sure book file is closed before we leave
[stockfish] / src / uci.cpp
index 4aade3b66bb99cbcdb261089519443f7c8e48c11..9c13eff7abfdf2ced889d5273c3e1e3651160284 100644 (file)
@@ -22,6 +22,7 @@
 //// Includes
 ////
 
+#include <cassert>
 #include <iostream>
 #include <sstream>
 #include <string>
@@ -118,7 +119,6 @@ namespace {
 
     if (token == "quit")
     {
-        OpeningBook.close();
         stop_threads();
         quit_eval();
         exit(0);
@@ -169,7 +169,7 @@ namespace {
     }
     else if (token == "key")
     {
-        std::cout << "key: " << RootPosition.get_key()
+        std::cout << "key: " << std::hex << RootPosition.get_key()
                   << " material key: " << RootPosition.get_material_key()
                   << " pawn key: " << RootPosition.get_pawn_key()
                   << std::endl;
@@ -219,15 +219,18 @@ namespace {
         if (token == "moves")
         {
             Move move;
-            UndoInfo u;
+            StateInfo st;
             while (!uip.eof())
             {
                 uip >> token;
                 move = move_from_string(RootPosition, token);
-                RootPosition.do_move(move, u);
+                RootPosition.do_move(move, st);
                 if (RootPosition.rule_50_counter() == 0)
                     RootPosition.reset_game_ply();
             }
+            // Our StateInfo st is about going out of scope,
+            // so save its content before they disappear.
+            RootPosition.setStartState(st);
         }
     }
   }
@@ -247,11 +250,13 @@ namespace {
     if (token == "name")
     {
         uip >> name;
-        uip >> token;
-        while (!uip.eof() && token != "value")
+        while (!uip.eof())
         {
-          name += (" " + token);
-          uip >> token;
+            uip >> token;
+            if (token == "value")
+                break;
+
+            name += (" " + token);
         }
         if (token == "value")
         {
@@ -321,6 +326,8 @@ namespace {
     if (moveTime)
         infinite = true;  // HACK
 
+    assert(RootPosition.is_ok());
+
     think(RootPosition, infinite, ponder, RootPosition.side_to_move(), time,
           inc, movesToGo, depth, nodes, moveTime, searchMoves);
   }