]> git.sesse.net Git - stockfish/commitdiff
Extend full 3 fold detection to PvNodes
authorMarco Costalba <mcostalba@gmail.com>
Fri, 26 Oct 2012 09:08:06 +0000 (11:08 +0200)
committerMarco Costalba <mcostalba@gmail.com>
Fri, 26 Oct 2012 09:56:33 +0000 (11:56 +0200)
And restore old behaviour of not returning from a RootNode
without updating RootMoves[].

Also renamed is_draw() template parameters to reflect a
'positive' logic (Check instead of Skip) that is easier
to follow.

New bench: 5312693

src/position.cpp
src/position.h
src/search.cpp

index feaeee22c606309a474c917bad77bfcc310d9b5d..40ea30f79f520d6d74ff0fa4de9cfd64e2b20e3b 100644 (file)
@@ -1467,39 +1467,31 @@ Value Position::compute_non_pawn_material(Color c) const {
 /// Position::is_draw() tests whether the position is drawn by material,
 /// repetition, or the 50 moves rule. It does not detect stalemates, this
 /// must be done by the search.
 /// Position::is_draw() tests whether the position is drawn by material,
 /// repetition, or the 50 moves rule. It does not detect stalemates, this
 /// must be done by the search.
-template<bool SkipRepetition, bool SkipThreeFoldCheck>
+template<bool CheckRepetition, bool CheckThreeFold>
 bool Position::is_draw() const {
 
 bool Position::is_draw() const {
 
-  // Draw by material?
   if (   !pieces(PAWN)
       && (non_pawn_material(WHITE) + non_pawn_material(BLACK) <= BishopValueMg))
       return true;
 
   if (   !pieces(PAWN)
       && (non_pawn_material(WHITE) + non_pawn_material(BLACK) <= BishopValueMg))
       return true;
 
-  // Draw by the 50 moves rule?
   if (st->rule50 > 99 && (!in_check() || MoveList<LEGAL>(*this).size()))
       return true;
 
   if (st->rule50 > 99 && (!in_check() || MoveList<LEGAL>(*this).size()))
       return true;
 
-  // Draw by repetition?
-  if (!SkipRepetition)
+  if (CheckRepetition)
   {
   {
-      int i = 4, e = std::min(st->rule50, st->pliesFromNull), rep_count=0;
+      int i = 4, e = std::min(st->rule50, st->pliesFromNull);
 
       if (i <= e)
       {
           StateInfo* stp = st->previous->previous;
 
 
       if (i <= e)
       {
           StateInfo* stp = st->previous->previous;
 
-          do {
+          for (int cnt = 0; i <= e; i += 2)
+          {
               stp = stp->previous->previous;
 
               stp = stp->previous->previous;
 
-              if (stp->key == st->key)
-              {
-                if(SkipThreeFoldCheck) return true;
-                else if(++rep_count>=2) return true;
-              }
-
-              i +=2;
-
-          } while (i <= e);
+              if (stp->key == st->key && (!CheckThreeFold || ++cnt >= 2))
+                  return true;
+          }
       }
   }
 
       }
   }
 
@@ -1507,8 +1499,8 @@ bool Position::is_draw() const {
 }
 
 // Explicit template instantiations
 }
 
 // Explicit template instantiations
-template bool Position::is_draw<false,true>() const;
-template bool Position::is_draw<true,true>() const;
+template bool Position::is_draw<true,  true>() const;
+template bool Position::is_draw<true, false>() const;
 template bool Position::is_draw<false,false>() const;
 
 
 template bool Position::is_draw<false,false>() const;
 
 
index ce636fe390b80ddd1162f1aea8ff0e63c2f47491..3014b2354b91f12e0c538a8efae7d9d986afbca6 100644 (file)
@@ -183,7 +183,7 @@ public:
   Thread* this_thread() const;
   int64_t nodes_searched() const;
   void set_nodes_searched(int64_t n);
   Thread* this_thread() const;
   int64_t nodes_searched() const;
   void set_nodes_searched(int64_t n);
-  template<bool SkipRepetition, bool SkipThreeFoldCheck> bool is_draw() const;
+  template<bool CheckRepetition, bool CheckThreeFold> bool is_draw() const;
 
   // Position consistency check, for debugging
   bool pos_is_ok(int* failedStep = NULL) const;
 
   // Position consistency check, for debugging
   bool pos_is_ok(int* failedStep = NULL) const;
index 9980dcf95b1aeb347986ce6cab2e6ac2000fe00f..2edaff8c2d1af5d79840f129713d0f2af65f810b 100644 (file)
@@ -524,7 +524,7 @@ namespace {
     if (!RootNode)
     {
         // Step 2. Check for aborted search and immediate draw
     if (!RootNode)
     {
         // Step 2. Check for aborted search and immediate draw
-        if (Signals.stop || pos.is_draw<false,true>() || ss->ply > MAX_PLY)
+        if (Signals.stop || pos.is_draw<true, PvNode>() || ss->ply > MAX_PLY)
             return DrawValue[pos.side_to_move()];
 
         // Step 3. Mate distance pruning. Even if we mate at the next move our score
             return DrawValue[pos.side_to_move()];
 
         // Step 3. Mate distance pruning. Even if we mate at the next move our score
@@ -538,10 +538,6 @@ namespace {
         if (alpha >= beta)
             return alpha;
     }
         if (alpha >= beta)
             return alpha;
     }
-       else 
-       {
-               if(pos.is_draw<false,false>()) return DrawValue[pos.side_to_move()];
-       }
 
     // Step 4. Transposition table lookup
     // We don't want the score of a partial search to overwrite a previous full search
 
     // Step 4. Transposition table lookup
     // We don't want the score of a partial search to overwrite a previous full search
@@ -1107,7 +1103,7 @@ split_point_start: // At split points actual search starts from here
     ss->ply = (ss-1)->ply + 1;
 
     // Check for an instant draw or maximum ply reached
     ss->ply = (ss-1)->ply + 1;
 
     // Check for an instant draw or maximum ply reached
-    if (pos.is_draw<true,true>() || ss->ply > MAX_PLY)
+    if (pos.is_draw<false, false>() || ss->ply > MAX_PLY)
         return DrawValue[pos.side_to_move()];
 
     // Transposition table lookup. At PV nodes, we don't use the TT for
         return DrawValue[pos.side_to_move()];
 
     // Transposition table lookup. At PV nodes, we don't use the TT for
@@ -1556,7 +1552,7 @@ void RootMove::extract_pv_from_tt(Position& pos) {
          && pos.is_pseudo_legal(m)
          && pos.pl_move_is_legal(m, pos.pinned_pieces())
          && ply < MAX_PLY
          && pos.is_pseudo_legal(m)
          && pos.pl_move_is_legal(m, pos.pinned_pieces())
          && ply < MAX_PLY
-         && (!pos.is_draw<false,true>() || ply < 2))
+         && (!pos.is_draw<true, true>() || ply < 2))
   {
       pv.push_back(m);
       pos.do_move(m, *st++);
   {
       pv.push_back(m);
       pos.do_move(m, *st++);