]> git.sesse.net Git - stockfish/commitdiff
Use a set to store SearchMoves
authorMarco Costalba <mcostalba@gmail.com>
Sat, 14 Jan 2012 10:45:54 +0000 (11:45 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sat, 14 Jan 2012 12:06:01 +0000 (13:06 +0100)
We just need to verify if a legal move is among the
SearchMoves, so we don't need a vector for this.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/benchmark.cpp
src/search.cpp
src/search.h
src/thread.cpp
src/thread.h
src/uci.cpp

index b43f0ee527392af234c9490e96ca2e560a3d40a5..1491e222ea4b108bb726bdb557b7feae12349baa 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <fstream>
 #include <iostream>
 
 #include <fstream>
 #include <iostream>
+#include <set>
 #include <vector>
 
 #include "misc.h"
 #include <vector>
 
 #include "misc.h"
@@ -121,7 +122,7 @@ void benchmark(int argc, char* argv[]) {
       }
       else
       {
       }
       else
       {
-          Threads.start_thinking(pos, limits, vector<Move>(), false);
+          Threads.start_thinking(pos, limits, set<Move>(), false);
           nodes += RootPosition.nodes_searched();
       }
   }
           nodes += RootPosition.nodes_searched();
       }
   }
index 86a8defd53898aa49de8ce1eefd1f9b12b64075d..0839bd0fcc73999bc245b441abe083157d83b3ee 100644 (file)
@@ -42,7 +42,7 @@ namespace Search {
 
   volatile SignalsType Signals;
   LimitsType Limits;
 
   volatile SignalsType Signals;
   LimitsType Limits;
-  std::vector<Move> SearchMoves;
+  std::set<Move> SearchMoves;
   Position RootPosition;
 }
 
   Position RootPosition;
 }
 
@@ -282,6 +282,7 @@ void Search::think() {
 
   static Book book; // Defined static to initialize the PRNG only once
 
 
   static Book book; // Defined static to initialize the PRNG only once
 
+  Move bm;
   Position& pos = RootPosition;
   Chess960 = pos.is_chess960();
   elapsed_time(true);
   Position& pos = RootPosition;
   Chess960 = pos.is_chess960();
   elapsed_time(true);
@@ -293,18 +294,24 @@ void Search::think() {
   // Populate RootMoves with all the legal moves (default) or, if a SearchMoves
   // is given, with the subset of legal moves to search.
   for (MoveList<MV_LEGAL> ml(pos); !ml.end(); ++ml)
   // Populate RootMoves with all the legal moves (default) or, if a SearchMoves
   // is given, with the subset of legal moves to search.
   for (MoveList<MV_LEGAL> ml(pos); !ml.end(); ++ml)
-      if (SearchMoves.empty() || count(SearchMoves.begin(), SearchMoves.end(), ml.move()))
+      if (SearchMoves.empty() || SearchMoves.count(ml.move()))
           RootMoves.push_back(RootMove(ml.move()));
 
           RootMoves.push_back(RootMove(ml.move()));
 
-  if (Options["OwnBook"])
+  if (RootMoves.empty())
   {
   {
-      Move bookMove = book.probe(pos, Options["Book File"], Options["Best Book Move"]);
+      cout << "info depth 0 score "
+           << score_to_uci(pos.in_check() ? -VALUE_MATE : VALUE_DRAW) << endl;
 
 
-      if (bookMove && count(RootMoves.begin(), RootMoves.end(), bookMove))
-      {
-          std::swap(RootMoves[0], *find(RootMoves.begin(), RootMoves.end(), bookMove));
-          goto finalize;
-      }
+      RootMoves.push_back(MOVE_NONE);
+      goto finalize;
+  }
+
+  if (   Options["OwnBook"]
+      && (bm = book.probe(pos, Options["Book File"], Options["Best Book Move"])) != MOVE_NONE
+      && count(RootMoves.begin(), RootMoves.end(), bm))
+  {
+      std::swap(RootMoves[0], *find(RootMoves.begin(), RootMoves.end(), bm));
+      goto finalize;
   }
 
   // Read UCI options: GUI could change UCI parameters during the game
   }
 
   // Read UCI options: GUI could change UCI parameters during the game
@@ -375,9 +382,9 @@ void Search::think() {
 
 finalize:
 
 
 finalize:
 
-  // When we reach max depth we arrive here even without a StopRequest, but if
-  // we are pondering or in infinite search, we shouldn't print the best move
-  // before we are told to do so.
+  // When we reach max depth we arrive here even without Signals.stop is raised,
+  // but if we are pondering or in infinite search, we shouldn't print the best
+  // move before we are told to do so.
   if (!Signals.stop && (Limits.ponder || Limits.infinite))
       Threads.wait_for_stop_or_ponderhit();
 
   if (!Signals.stop && (Limits.ponder || Limits.infinite))
       Threads.wait_for_stop_or_ponderhit();
 
@@ -406,16 +413,6 @@ namespace {
     bestValue = delta = -VALUE_INFINITE;
     ss->currentMove = MOVE_NULL; // Hack to skip update gains
 
     bestValue = delta = -VALUE_INFINITE;
     ss->currentMove = MOVE_NULL; // Hack to skip update gains
 
-    // Handle the special case of a mated/stalemate position
-    if (RootMoves.empty())
-    {
-        cout << "info depth 0 score "
-             << score_to_uci(pos.in_check() ? -VALUE_MATE : VALUE_DRAW) << endl;
-
-        RootMoves.push_back(MOVE_NONE);
-        return;
-    }
-
     // Iterative deepening loop until requested to stop or target depth reached
     while (!Signals.stop && ++depth <= MAX_PLY && (!Limits.maxDepth || depth <= Limits.maxDepth))
     {
     // Iterative deepening loop until requested to stop or target depth reached
     while (!Signals.stop && ++depth <= MAX_PLY && (!Limits.maxDepth || depth <= Limits.maxDepth))
     {
index 8290b41a70f6a49f874df4c64c28341e5614d45f..d805d4629424cf9a991ee1b06d8eb979d0dbdcc3 100644 (file)
@@ -21,7 +21,7 @@
 #define SEARCH_H_INCLUDED
 
 #include <cstring>
 #define SEARCH_H_INCLUDED
 
 #include <cstring>
-#include <vector>
+#include <set>
 
 #include "types.h"
 
 
 #include "types.h"
 
@@ -70,7 +70,7 @@ struct SignalsType {
 
 extern volatile SignalsType Signals;
 extern LimitsType Limits;
 
 extern volatile SignalsType Signals;
 extern LimitsType Limits;
-extern std::vector<Move> SearchMoves;
+extern std::set<Move> SearchMoves;
 extern Position RootPosition;
 
 extern void init();
 extern Position RootPosition;
 
 extern void init();
index 99976b12f7e6d693068bf8656ff934f9b2142c39..74ca48cc7e81ea175f734f31b9fb26828320067b 100644 (file)
@@ -431,7 +431,7 @@ void Thread::main_loop() {
 // the search to finish.
 
 void ThreadsManager::start_thinking(const Position& pos, const LimitsType& limits,
 // the search to finish.
 
 void ThreadsManager::start_thinking(const Position& pos, const LimitsType& limits,
-                                    const std::vector<Move>& searchMoves, bool asyncMode) {
+                                    const std::set<Move>& searchMoves, bool asyncMode) {
   Thread& main = threads[0];
 
   lock_grab(&main.sleepLock);
   Thread& main = threads[0];
 
   lock_grab(&main.sleepLock);
index 48da805b641cb5aca9e985238954c0873712dda2..6bccde4c4671425cbd1f1c279c3e1f9c6a5b2f75 100644 (file)
@@ -21,6 +21,7 @@
 #define THREAD_H_INCLUDED
 
 #include <cstring>
 #define THREAD_H_INCLUDED
 
 #include <cstring>
+#include <set>
 
 #include "lock.h"
 #include "material.h"
 
 #include "lock.h"
 #include "material.h"
@@ -120,7 +121,7 @@ public:
   void wait_for_stop_or_ponderhit();
   void stop_thinking();
   void start_thinking(const Position& pos, const Search::LimitsType& limits,
   void wait_for_stop_or_ponderhit();
   void stop_thinking();
   void start_thinking(const Position& pos, const Search::LimitsType& limits,
-                      const std::vector<Move>& searchMoves, bool asyncMode);
+                      const std::set<Move>& searchMoves, bool asyncMode);
 
   template <bool Fake>
   Value split(Position& pos, Search::Stack* ss, Value alpha, Value beta, Value bestValue,
 
   template <bool Fake>
   Value split(Position& pos, Search::Stack* ss, Value alpha, Value beta, Value bestValue,
index 6bc387c1848ceacf9890d2b5d6d1fe3511a7819b..ceb04dc3cf21a9f9ae92c618366c37e9fc085380 100644 (file)
@@ -201,7 +201,7 @@ namespace {
 
     string token;
     Search::LimitsType limits;
 
     string token;
     Search::LimitsType limits;
-    std::vector<Move> searchMoves;
+    std::set<Move> searchMoves;
     int time[] = { 0, 0 }, inc[] = { 0, 0 };
 
     while (is >> token)
     int time[] = { 0, 0 }, inc[] = { 0, 0 };
 
     while (is >> token)
@@ -228,7 +228,7 @@ namespace {
             is >> limits.maxTime;
         else if (token == "searchmoves")
             while (is >> token)
             is >> limits.maxTime;
         else if (token == "searchmoves")
             while (is >> token)
-                searchMoves.push_back(move_from_uci(pos, token));
+                searchMoves.insert(move_from_uci(pos, token));
     }
 
     limits.time = time[pos.side_to_move()];
     }
 
     limits.time = time[pos.side_to_move()];