Merge official-stockfish/master
authorFabian Fichter <ianfab@users.noreply.github.com>
Thu, 13 Jun 2019 20:09:05 +0000 (22:09 +0200)
committerFabian Fichter <ianfab@users.noreply.github.com>
Thu, 13 Jun 2019 20:09:05 +0000 (22:09 +0200)
No functional change.

1  2 
src/position.cpp
src/position.h

@@@ -1274,6 -879,25 +1274,25 @@@ void Position::do_move(Move m, StateInf
    // Update king attacks used for fast check detection
    set_check_info(st);
  
+   // Calculate the repetition info. It is the ply distance from the previous
+   // occurrence of the same position, negative in the 3-fold case, or zero
+   // if the position was not repeated.
+   st->repetition = 0;
 -  int end = std::min(st->rule50, st->pliesFromNull);
++  int end = captures_to_hand() ? st->pliesFromNull : std::min(st->rule50, st->pliesFromNull);
+   if (end >= 4)
+   {
+       StateInfo* stp = st->previous->previous;
+       for (int i=4; i <= end; i += 2)
+       {
+           stp = stp->previous->previous;
+           if (stp->key == st->key)
+           {
+               st->repetition = stp->repetition ? -i : i;
+               break;
+           }
+       }
+   }
    assert(pos_is_ok());
  }
  
@@@ -1732,23 -1153,11 +1753,11 @@@ bool Position::is_immediate_game_end(Va
  bool Position::has_repeated() const {
  
      StateInfo* stc = st;
-     while (true)
 -    int end = std::min(st->rule50, st->pliesFromNull);
++    int end = captures_to_hand() ? st->pliesFromNull : std::min(st->rule50, st->pliesFromNull);
+     while (end-- >= 4)
      {
-         int i = 4, end = std::min(stc->rule50, stc->pliesFromNull);
-         if (end < i)
-             return false;
-         StateInfo* stp = stc->previous->previous;
-         do {
-             stp = stp->previous->previous;
-             if (stp->key == stc->key)
-                 return true;
-             i += 2;
-         } while (i <= end);
+         if (stc->repetition)
+             return true;
  
          stc = stc->previous;
      }
@@@ -1762,9 -1172,9 +1772,9 @@@ bool Position::has_game_cycle(int ply) 
  
    int j;
  
--  int end = std::min(st->rule50, st->pliesFromNull);
++  int end = captures_to_hand() ? st->pliesFromNull : std::min(st->rule50, st->pliesFromNull);
  
 -  if (end < 3)
 +  if (end < 3 || var->nFoldValue != VALUE_DRAW)
      return false;
  
    Key originalKey = st->key;
diff --cc src/position.h
Simple merge