]> git.sesse.net Git - stockfish/commitdiff
Moved the code for extracting the PV from the TT to tt.cpp, where
authorTord Romstad <tord@glaurungchess.com>
Thu, 6 Aug 2009 12:02:53 +0000 (14:02 +0200)
committerTord Romstad <tord@glaurungchess.com>
Thu, 6 Aug 2009 12:02:53 +0000 (14:02 +0200)
it belongs.

src/search.cpp
src/tt.cpp
src/tt.h

index d922986b7fd7b3744441e92e352391925dd5d967..15757c3a9ae7c025cc02f5c616380cc00976fc29 100644 (file)
@@ -306,7 +306,6 @@ namespace {
   void update_history(const Position& pos, Move m, Depth depth, Move movesSearched[], int moveCount);
   void update_killers(Move m, SearchStack& ss);
   void slowdown(const Position& pos);
-  void build_pv(const Position& pos, Move pv[]);
 
   bool fail_high_ply_1();
   int current_search_time();
@@ -976,7 +975,7 @@ namespace {
             // Update PV
             rml.set_move_score(i, value);
             update_pv(ss, 0);
-            build_pv(pos, ss[0].pv);
+            TT.extract_pv(pos, ss[0].pv);
             rml.set_move_pv(i, ss[0].pv);
 
             if (MultiPV == 1)
@@ -2446,37 +2445,6 @@ namespace {
   }
 
 
-  // build_pv() extends a PV by adding moves from the transposition table at
-  // the end. This should ensure that the PV is almost always at least two
-  // plies long, which is important, because otherwise we will often get
-  // single-move PVs when the search stops while failing high, and a
-  // single-move PV means that we don't have a ponder move.
-
-  void build_pv(const Position& pos, Move pv[]) {
-    int ply;
-    Position p(pos);
-    StateInfo st[100];
-
-    for (ply = 0; pv[ply] != MOVE_NONE; ply++)
-        p.do_move(pv[ply], st[ply]);
-
-    bool stop;
-    const TTEntry* tte;
-    for (stop = false, tte = TT.retrieve(p.get_key());
-         tte && tte->move() != MOVE_NONE && !stop;
-         tte = TT.retrieve(p.get_key()), ply++)
-    {
-        if (!move_is_legal(p, tte->move(), p.pinned_pieces(p.side_to_move())))
-            break;
-        pv[ply] = tte->move();
-        p.do_move(pv[ply], st[ply]);
-        for (int j = 0; j < ply; j++)
-            if (st[j].key == p.get_key()) stop = true;
-    }
-    pv[ply] = MOVE_NONE;
-  }
-
-
   // fail_high_ply_1() checks if some thread is currently resolving a fail
   // high at ply 1 at the node below the first root node.  This information
   // is used for time managment.
index 3651cbb294901529ba9089fc80700cba526a9613..c1a8b1b950b24edbc514fdb43baaae2dc6909288 100644 (file)
@@ -26,6 +26,7 @@
 #include <cmath>
 #include <cstring>
 
+#include "movegen.h"
 #include "tt.h"
 
 
@@ -185,6 +186,38 @@ void TranspositionTable::insert_pv(const Position& pos, Move pv[]) {
 }
 
 
+/// TranspositionTable::extract_pv() extends a PV by adding moves from the
+/// transposition table at the end. This should ensure that the PV is almost
+/// always at least two plies long, which is important, because otherwise we
+/// will often get single-move PVs when the search stops while failing high,
+/// and a single-move PV means that we don't have a ponder move.
+
+void TranspositionTable::extract_pv(const Position& pos, Move pv[]) {
+
+  int ply;
+  Position p(pos);
+  StateInfo st[100];
+
+  for (ply = 0; pv[ply] != MOVE_NONE; ply++)
+      p.do_move(pv[ply], st[ply]);
+
+  bool stop;
+  const TTEntry* tte;
+  for (stop = false, tte = retrieve(p.get_key());
+       tte && tte->move() != MOVE_NONE && !stop;
+       tte = retrieve(p.get_key()), ply++)
+  {
+      if (!move_is_legal(p, tte->move(), p.pinned_pieces(p.side_to_move())))
+          break;
+      pv[ply] = tte->move();
+      p.do_move(pv[ply], st[ply]);
+      for (int j = 0; j < ply; j++)
+          if (st[j].key == p.get_key()) stop = true;
+  }
+  pv[ply] = MOVE_NONE;
+}
+
+
 /// TranspositionTable::full() returns the permill of all transposition table
 /// entries which have received at least one write during the current search.
 /// It is used to display the "info hashfull ..." information in UCI.
index fb414bf157aeba9fa98fbe70bbb728cd27445e1e..08121f66f699a9bcf7e6b1e54893b0636f75f80b 100644 (file)
--- a/src/tt.h
+++ b/src/tt.h
@@ -87,6 +87,7 @@ public:
   TTEntry* retrieve(const Key posKey) const;
   void new_search();
   void insert_pv(const Position& pos, Move pv[]);
+  void extract_pv(const Position& pos, Move pv[]);
   int full() const;
 
 private: