From: Fabian Fichter Date: Thu, 13 Jun 2019 20:09:05 +0000 (+0200) Subject: Merge official-stockfish/master X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=5a8b0300098703934bcd70d5644d59bdba6fc43c;p=fairystockfish.git Merge official-stockfish/master No functional change. --- 5a8b0300098703934bcd70d5644d59bdba6fc43c diff --cc src/position.cpp index 881cee9,901e91a..f4c4b99 --- a/src/position.cpp +++ b/src/position.cpp @@@ -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;