]> git.sesse.net Git - stockfish/commitdiff
Use C++ loops in insert_pv_in_tt
authorMarco Costalba <mcostalba@gmail.com>
Sat, 31 Jan 2015 11:31:00 +0000 (12:31 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sat, 31 Jan 2015 11:57:52 +0000 (12:57 +0100)
Also small tweak to extract_ponder_from_tt

No functional change.

src/search.cpp
src/search.h

index 6d630ff70abbf35bf9d3556f70c7bed1a8dd9d3d..da8f457d6f01bdfeab1283237b2bf641115c3b31 100644 (file)
@@ -1461,22 +1461,22 @@ string UCI::pv(const Position& pos, Depth depth, Value alpha, Value beta) {
 void RootMove::insert_pv_in_tt(Position& pos) {
 
   StateInfo state[MAX_PLY], *st = state;
-  size_t idx = 0;
+  bool ttHit;
 
-  for ( ; idx < pv.size(); ++idx)
+  for (Move m : pv)
   {
-      bool ttHit;
-      TTEntry* tte = TT.probe(pos.key(), ttHit);
+      assert(MoveList<LEGAL>(pos).contains(m));
 
-      if (!ttHit || tte->move() != pv[idx]) // Don't overwrite correct entries
-          tte->save(pos.key(), VALUE_NONE, BOUND_NONE, DEPTH_NONE, pv[idx], VALUE_NONE, TT.generation());
+      TTEntry* tte = TT.probe(pos.key(), ttHit);
 
-      assert(MoveList<LEGAL>(pos).contains(pv[idx]));
+      if (!ttHit || tte->move() != m) // Don't overwrite correct entries
+          tte->save(pos.key(), VALUE_NONE, BOUND_NONE, DEPTH_NONE, m, VALUE_NONE, TT.generation());
 
-      pos.do_move(pv[idx], *st++);
+      pos.do_move(m, *st++);
   }
 
-  while (idx) pos.undo_move(pv[--idx]);
+  for (size_t i = pv.size(); i > 0; )
+      pos.undo_move(pv[--i]);
 }
 
 
@@ -1485,22 +1485,25 @@ void RootMove::insert_pv_in_tt(Position& pos) {
 /// root. We try hard to have a ponder move to return to the GUI, otherwise in case of
 /// 'ponder on' we have nothing to think on.
 
-Move RootMove::extract_ponder_from_tt(Position& pos)
+bool RootMove::extract_ponder_from_tt(Position& pos)
 {
     StateInfo st;
-    bool found;
+    bool ttHit;
 
     assert(pv.size() == 1);
 
     pos.do_move(pv[0], st);
-    TTEntry* tte = TT.probe(pos.key(), found);
-    Move m = found ? tte->move() : MOVE_NONE;
-    if (!MoveList<LEGAL>(pos).contains(m))
-        m = MOVE_NONE;
-
+    TTEntry* tte = TT.probe(pos.key(), ttHit);
     pos.undo_move(pv[0]);
-    pv.push_back(m);
-    return m;
+
+    if (ttHit)
+    {
+        Move m = tte->move(); // Local copy to be SMP safe
+        if (MoveList<LEGAL>(pos).contains(m))
+           return pv.push_back(m), true;
+    }
+
+    return false;
 }
 
 
index 3d348de94b2b860d5d461b5b287c05f2496e1b6a..32cd1bed0ea714ac114cea16e85c957f504bf124 100644 (file)
@@ -60,7 +60,7 @@ struct RootMove {
   bool operator<(const RootMove& m) const { return score > m.score; } // Ascending sort
   bool operator==(const Move& m) const { return pv[0] == m; }
   void insert_pv_in_tt(Position& pos);
-  Move extract_ponder_from_tt(Position& pos);
+  bool extract_ponder_from_tt(Position& pos);
 
   Value score;
   Value previousScore;