]> git.sesse.net Git - stockfish/blobdiff - src/uci.cpp
Be sure book file is closed before we leave
[stockfish] / src / uci.cpp
index 1a2c05a40fccbc007b0f384f5ba2af3610d122dc..9c13eff7abfdf2ced889d5273c3e1e3651160284 100644 (file)
@@ -1,13 +1,14 @@
 /*
-  Glaurung, a UCI chess playing engine.
-  Copyright (C) 2004-2008 Tord Romstad
+  Stockfish, a UCI chess playing engine derived from Glaurung 2.1
+  Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
+  Copyright (C) 2008 Marco Costalba
 
-  Glaurung is free software: you can redistribute it and/or modify
+  Stockfish is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.
 
-  Glaurung is distributed in the hope that it will be useful,
+  Stockfish is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
@@ -21,6 +22,7 @@
 //// Includes
 ////
 
+#include <cassert>
 #include <iostream>
 #include <sstream>
 #include <string>
@@ -89,7 +91,7 @@ namespace {
   // get_command() waits for a command from the user, and passes
   // this command to handle_command.  get_command also intercepts
   // EOF from stdin, by translating EOF to the "quit" command.  This
-  // ensures that Glaurung exits gracefully if the GUI dies
+  // ensures that Stockfish exits gracefully if the GUI dies
   // unexpectedly.
 
   void get_command() {
@@ -117,15 +119,15 @@ namespace {
 
     if (token == "quit")
     {
-        OpeningBook.close();
         stop_threads();
         quit_eval();
         exit(0);
     }
     else if (token == "uci")
     {
-        std::cout << "id name " << engine_name() << std::endl;
-        std::cout << "id author Tord Romstad" << std::endl;
+        std::cout << "id name " << engine_name() << std::endl
+                  << "id author Tord Romstad, Marco Costalba"
+                  << std::endl;
         print_uci_options();
         std::cout << "uciok" << std::endl;
     }
@@ -134,7 +136,6 @@ namespace {
         TT.clear();
         Position::init_piece_square_tables();
         RootPosition.from_fen(StartPosition);
-
     }
     else if (token == "isready")
         std::cout << "readyok" << std::endl;
@@ -168,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;
@@ -185,7 +186,7 @@ namespace {
   }
 
 
-  // set_position() is called when Glaurung receives the "position" UCI
+  // set_position() is called when Stockfish receives the "position" UCI
   // command.  The input parameter is a UCIInputParser.  It is assumed
   // that this parser has consumed the first token of the UCI command
   // ("position"), and is ready to read the second token ("startpos"
@@ -218,21 +219,24 @@ 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);
         }
     }
   }
 
 
-  // set_option() is called when Glaurung receives the "setoption" UCI
+  // set_option() is called when Stockfish receives the "setoption" UCI
   // command.  The input parameter is a UCIInputParser.  It is assumed
   // that this parser has consumed the first token of the UCI command
   // ("setoption"), and is ready to read the second token ("name", if
@@ -246,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")
         {
@@ -262,7 +268,7 @@ namespace {
   }
 
 
-  // go() is called when Glaurung receives the "go" UCI command.  The
+  // go() is called when Stockfish receives the "go" UCI command.  The
   // input parameter is a UCIInputParser.  It is assumed that this
   // parser has consumed the first token of the UCI command ("go"),
   // and is ready to read the second token.  The function sets the
@@ -320,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);
   }