]> git.sesse.net Git - stockfish/commitdiff
Shrink Position::is_draw()
authorMarco Costalba <mcostalba@gmail.com>
Tue, 3 Dec 2013 10:37:29 +0000 (11:37 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Tue, 3 Dec 2013 10:40:31 +0000 (11:40 +0100)
No functional change.

src/position.cpp

index 6088477d1ef182c9490f215771ed5f139b4d080e..3b59b24a19171190c1d7d62acd93e6faeaf11968 100644 (file)
@@ -1229,35 +1229,25 @@ 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, 50 moves
+/// rule or repetition. It does not detect stalemates.
+
 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 && (!checkers() || MoveList<LEGAL>(*this).size()))
       return true;
 
   if (st->rule50 > 99 && (!checkers() || MoveList<LEGAL>(*this).size()))
       return true;
 
-  int i = 4, e = std::min(st->rule50, st->pliesFromNull);
-
-  if (i <= e)
+  StateInfo* stp = st;
+  for (int i = 2, e = std::min(st->rule50, st->pliesFromNull); i <= e; i += 2)
   {
   {
-      StateInfo* stp = st->previous->previous;
-
-      do {
-          stp = stp->previous->previous;
-
-          if (stp->key == st->key)
-              return true; // Draw after first repetition
-
-          i += 2;
+      stp = stp->previous->previous;
 
 
-      } while (i <= e);
+      if (stp->key == st->key)
+          return true; // Draw at first repetition
   }
 
   return false;
   }
 
   return false;