]> git.sesse.net Git - stockfish/blobdiff - src/position.cpp
Start searching for a repetition from the 4th ply behind
[stockfish] / src / position.cpp
index 325ffd1114892aa0e4f1598acc74bc877d430adf..fd518488e3384c38397243bd0610dab6134af73f 100644 (file)
@@ -1079,14 +1079,20 @@ bool Position::is_draw() const {
   if (st->rule50 > 99 && (!checkers() || MoveList<LEGAL>(*this).size()))
       return true;
 
-  StateInfo* stp = st;
-  for (int i = 2, e = std::min(st->rule50, st->pliesFromNull); i <= e; i += 2)
-  {
+  int e = std::min(st->rule50, st->pliesFromNull);
+
+  if (e < 4)
+    return false;
+
+  StateInfo* stp = st->previous->previous;
+
+  do {
       stp = stp->previous->previous;
 
       if (stp->key == st->key)
           return true; // Draw at first repetition
-  }
+
+  } while ((e -= 2) >= 4);
 
   return false;
 }