]> git.sesse.net Git - stockfish/commitdiff
Move SearchStack under Search namespace
authorMarco Costalba <mcostalba@gmail.com>
Sun, 4 Dec 2011 10:46:31 +0000 (11:46 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sun, 4 Dec 2011 11:03:59 +0000 (12:03 +0100)
No functional change.

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

index 2b20f25f002447861a6deeddbf6260af21114c2b..0b3b6fd6b0e4d1e88d9052036ce58e07f886d279 100644 (file)
@@ -72,7 +72,7 @@ namespace {
 /// move ordering is at the current node.
 
 MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const History& h,
-                       SearchStack* ss, Value beta) : pos(p), H(h), depth(d) {
+                       Search::Stack* ss, Value beta) : pos(p), H(h), depth(d) {
   captureThreshold = 0;
   badCaptures = moves + MAX_MOVES;
 
index 34329582d18854ed989a87f8119a824baec0db85..b2a8dc98bbe1b38096b27f78a984620bb24a9ebd 100644 (file)
 
 #include "history.h"
 #include "position.h"
+#include "search.h"
 #include "types.h"
 
-struct SearchStack;
-
 /// MovePicker is a class which is used to pick one pseudo legal move at a time
 /// from the current position. It is initialized with a Position object and a few
 /// moves we have reason to believe are good. The most important method is
@@ -39,7 +38,7 @@ class MovePicker {
   MovePicker& operator=(const MovePicker&); // Silence a warning under MSVC
 
 public:
-  MovePicker(const Position&, Move, Depth, const History&, SearchStack*, Value);
+  MovePicker(const Position&, Move, Depth, const History&, Search::Stack*, Value);
   MovePicker(const Position&, Move, Depth, const History&, Square recaptureSq);
   MovePicker(const Position&, Move, const History&, PieceType parentCapture);
   Move get_next_move();
index e625405d5eec56d9759df974dfda90cc898aa2d8..77acd89e39b12310d5333708de19c5c85c7a883f 100644 (file)
 #include "tt.h"
 #include "ucioption.h"
 
-using std::cout;
-using std::endl;
-using std::string;
-using Search::Signals;
-using Search::Limits;
-
 namespace Search {
 
   volatile SignalsType Signals;
@@ -52,6 +46,11 @@ namespace Search {
   Position RootPosition;
 }
 
+using std::cout;
+using std::endl;
+using std::string;
+using namespace Search;
+
 namespace {
 
   // Set to true to force running with one thread. Used for debugging
@@ -186,10 +185,10 @@ namespace {
   Move id_loop(Position& pos, Move rootMoves[], Move* ponderMove);
 
   template <NodeType NT>
-  Value search(Position& pos, SearchStack* ss, Value alpha, Value beta, Depth depth);
+  Value search(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth);
 
   template <NodeType NT>
-  Value qsearch(Position& pos, SearchStack* ss, Value alpha, Value beta, Depth depth);
+  Value qsearch(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth);
 
   bool check_is_dangerous(Position &pos, Move move, Value futilityBase, Value beta, Value *bValue);
   bool connected_moves(const Position& pos, Move m1, Move m2);
@@ -213,14 +212,14 @@ namespace {
   // we simply create and use a standard MovePicker object.
   template<bool SpNode> struct MovePickerExt : public MovePicker {
 
-    MovePickerExt(const Position& p, Move ttm, Depth d, const History& h, SearchStack* ss, Value b)
+    MovePickerExt(const Position& p, Move ttm, Depth d, const History& h, Stack* ss, Value b)
                   : MovePicker(p, ttm, d, h, ss, b) {}
   };
 
   // In case of a SpNode we use split point's shared MovePicker object as moves source
   template<> struct MovePickerExt<true> : public MovePicker {
 
-    MovePickerExt(const Position& p, Move ttm, Depth d, const History& h, SearchStack* ss, Value b)
+    MovePickerExt(const Position& p, Move ttm, Depth d, const History& h, Stack* ss, Value b)
                   : MovePicker(p, ttm, d, h, ss, b), mp(ss->sp->mp) {}
 
     Move get_next_move() { return mp->get_next_move(); }
@@ -487,7 +486,7 @@ namespace {
 
   Move id_loop(Position& pos, Move rootMoves[], Move* ponderMove) {
 
-    SearchStack ss[PLY_MAX_PLUS_2];
+    Stack ss[PLY_MAX_PLUS_2];
     Value bestValues[PLY_MAX_PLUS_2];
     int bestMoveChanges[PLY_MAX_PLUS_2];
     int depth, aspirationDelta;
@@ -496,7 +495,7 @@ namespace {
     bool bestMoveNeverChanged = true;
 
     // Initialize stuff before a new search
-    memset(ss, 0, 4 * sizeof(SearchStack));
+    memset(ss, 0, 4 * sizeof(Stack));
     TT.new_search();
     H.clear();
     *ponderMove = bestMove = skillBest = skillPonder = MOVE_NONE;
@@ -708,7 +707,7 @@ namespace {
   // here: This is taken care of after we return from the split point.
 
   template <NodeType NT>
-  Value search(Position& pos, SearchStack* ss, Value alpha, Value beta, Depth depth) {
+  Value search(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth) {
 
     const bool PvNode   = (NT == PV || NT == Root || NT == SplitPointPV || NT == SplitPointRoot);
     const bool SpNode   = (NT == SplitPointPV || NT == SplitPointNonPV || NT == SplitPointRoot);
@@ -1297,7 +1296,7 @@ split_point_start: // At split points actual search starts from here
   // less than ONE_PLY).
 
   template <NodeType NT>
-  Value qsearch(Position& pos, SearchStack* ss, Value alpha, Value beta, Depth depth) {
+  Value qsearch(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth) {
 
     const bool PvNode = (NT == PV);
 
@@ -2101,11 +2100,11 @@ void Thread::idle_loop(SplitPoint* sp) {
           assert(!do_terminate);
 
           // Copy split point position and search stack and call search()
-          SearchStack ss[PLY_MAX_PLUS_2];
+          Stack ss[PLY_MAX_PLUS_2];
           SplitPoint* tsp = splitPoint;
           Position pos(*tsp->pos, threadID);
 
-          memcpy(ss, tsp->ss - 1, 4 * sizeof(SearchStack));
+          memcpy(ss, tsp->ss - 1, 4 * sizeof(Stack));
           (ss+1)->sp = tsp;
 
           if (tsp->nodeType == Root)
index 53e7444c8ad205c5bb6cc34ce22e4b2009621d1f..02aaa652bdafdcb377ec0420d4e35c41d49c36e6 100644 (file)
 class Position;
 struct SplitPoint;
 
-/// The SearchStack struct keeps track of the information we need to remember
-/// from nodes shallower and deeper in the tree during the search.  Each
-/// search thread has its own array of SearchStack objects, indexed by the
-/// current ply.
+namespace Search {
+
+/// The Stack struct keeps track of the information we need to remember from
+/// nodes shallower and deeper in the tree during the search. Each search thread
+/// has its own array of Stack objects, indexed by the current ply.
 
-struct SearchStack {
+struct Stack {
   SplitPoint* sp;
   int ply;
   Move currentMove;
@@ -46,9 +47,8 @@ struct SearchStack {
   int skipNullMove;
 };
 
-namespace Search {
 
-/// The SearchLimits struct stores information sent by GUI about available time
+/// The LimitsType struct stores information sent by GUI about available time
 /// to search the current move, maximum depth/time, if we are in analysis mode
 /// or if we have to ponder while is our opponent's side to move.
 
@@ -60,6 +60,10 @@ struct LimitsType {
   int time, increment, movesToGo, maxTime, maxDepth, maxNodes, infinite, ponder;
 };
 
+
+/// The SignalsType struct stores volatile flags updated during the search
+/// typically in an async fashion, for instance to stop the search by the GUI.
+
 struct SignalsType {
   bool stopOnPonderhit, firstRootMove, stop, failedLowAtRoot;
 };
@@ -75,6 +79,4 @@ extern void think();
 
 } // namespace
 
-extern void do_timer_event();
-
 #endif // !defined(SEARCH_H_INCLUDED)
index 8af9dc414f1c35c1a53f1640cb3bf2a3e5f50cec..cf35c28857305b68c7b17ff768836b51d27956c1 100644 (file)
@@ -23,6 +23,8 @@
 #include "thread.h"
 #include "ucioption.h"
 
+using namespace Search;
+
 ThreadsManager Threads; // Global object
 
 namespace { extern "C" {
@@ -257,7 +259,7 @@ bool ThreadsManager::split_point_finished(SplitPoint* sp) const {
 // search(). When all threads have returned from search() then split() returns.
 
 template <bool Fake>
-Value ThreadsManager::split(Position& pos, SearchStack* ss, Value alpha, Value beta,
+Value ThreadsManager::split(Position& pos, Stack* ss, Value alpha, Value beta,
                             Value bestValue, Depth depth, Move threatMove,
                             int moveCount, MovePicker* mp, int nodeType) {
   assert(pos.pos_is_ok());
@@ -359,12 +361,13 @@ Value ThreadsManager::split(Position& pos, SearchStack* ss, Value alpha, Value b
 }
 
 // Explicit template instantiations
-template Value ThreadsManager::split<false>(Position&, SearchStack*, Value, Value, Value, Depth, Move, int, MovePicker*, int);
-template Value ThreadsManager::split<true>(Position&, SearchStack*, Value, Value, Value, Depth, Move, int, MovePicker*, int);
+template Value ThreadsManager::split<false>(Position&, Stack*, Value, Value, Value, Depth, Move, int, MovePicker*, int);
+template Value ThreadsManager::split<true>(Position&, Stack*, Value, Value, Value, Depth, Move, int, MovePicker*, int);
 
 
 // Thread::timer_loop() is where the timer thread waits maxPly milliseconds and
 // then calls do_timer_event(). If maxPly is 0 thread sleeps until is woken up.
+extern void do_timer_event();
 
 void Thread::timer_loop() {
 
@@ -417,7 +420,7 @@ void Thread::main_loop() {
       if (do_terminate)
           return;
 
-      Search::think(); // This is the search entry point
+      think(); // This is the search entry point
   }
 }
 
@@ -427,7 +430,7 @@ void Thread::main_loop() {
 // then function returns immediately, otherwise caller is blocked waiting for
 // the search to finish.
 
-void ThreadsManager::start_thinking(const Position& pos, const Search::LimitsType& limits,
+void ThreadsManager::start_thinking(const Position& pos, const LimitsType& limits,
                                     const std::vector<Move>& searchMoves, bool asyncMode) {
   Thread& main = threads[0];
 
@@ -438,12 +441,12 @@ void ThreadsManager::start_thinking(const Position& pos, const Search::LimitsTyp
       cond_wait(&sleepCond, &main.sleepLock);
 
   // Copy input arguments to initialize the search
-  Search::RootPosition.copy(pos, 0);
-  Search::Limits = limits;
-  Search::RootMoves = searchMoves;
+  RootPosition.copy(pos, 0);
+  Limits = limits;
+  RootMoves = searchMoves;
 
   // Reset signals before to start the new search
-  memset((void*)&Search::Signals, 0, sizeof(Search::Signals));
+  memset((void*)&Signals, 0, sizeof(Signals));
 
   main.do_sleep = false;
   cond_signal(&main.sleepCond); // Wake up main thread and start searching
@@ -464,13 +467,13 @@ void ThreadsManager::start_thinking(const Position& pos, const Search::LimitsTyp
 
 void ThreadsManager::wait_for_stop_or_ponderhit() {
 
-  Search::Signals.stopOnPonderhit = true;
+  Signals.stopOnPonderhit = true;
 
   Thread& main = threads[0];
 
   lock_grab(&main.sleepLock);
 
-  while (!Search::Signals.stop)
+  while (!Signals.stop)
       cond_wait(&main.sleepCond, &main.sleepLock);
 
   lock_release(&main.sleepLock);
index 13615c2c92daca51714ff5456491926b2b95fa8c..dcaa5ca3c29c66f662e55cbd1c16d778eea0bd23 100644 (file)
@@ -46,7 +46,7 @@ struct SplitPoint {
 
   // Const pointers to shared data
   MovePicker* mp;
-  SearchStack* ss;
+  Search::Stack* ss;
 
   // Shared data
   Lock lock;
@@ -122,7 +122,7 @@ public:
                       const std::vector<Move>& searchMoves, bool asyncMode);
 
   template <bool Fake>
-  Value split(Position& pos, SearchStack* ss, Value alpha, Value beta, Value bestValue,
+  Value split(Position& pos, Search::Stack* ss, Value alpha, Value beta, Value bestValue,
               Depth depth, Move threatMove, int moveCount, MovePicker* mp, int nodeType);
 private:
   friend struct Thread;