From: Fabian Fichter Date: Mon, 4 Mar 2019 19:54:56 +0000 (+0100) Subject: Fix detection of optional game end X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=b2d89b1c685f47549aa0927fceb09c58482b40bd;p=fairystockfish.git Fix detection of optional game end No functional change for variants without counting rules. --- diff --git a/src/position.cpp b/src/position.cpp index 45373a9..7c6c007 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -1570,27 +1570,27 @@ bool Position::is_optional_game_end(Value& result, int ply) const { { int end = captures_to_hand() ? st->pliesFromNull : std::min(st->rule50, st->pliesFromNull); - if (end < 4) - return false; - - StateInfo* stp = st->previous->previous; - int cnt = 0; - bool perpetual = true; - - for (int i = 4; i <= end; i += 2) + if (end >= 4) { - stp = stp->previous->previous; - perpetual &= bool(stp->checkersBB); + StateInfo* stp = st->previous->previous; + int cnt = 0; + bool perpetual = true; - // Return a draw score if a position repeats once earlier but strictly - // after the root, or repeats twice before or at the root. - if ( stp->key == st->key - && ++cnt + 1 == (ply > i ? 2 : n_fold_rule())) + for (int i = 4; i <= end; i += 2) { - result = convert_mate_value( var->perpetualCheckIllegal && perpetual ? VALUE_MATE - : var->nFoldValueAbsolute && sideToMove == BLACK ? -var->nFoldValue - : var->nFoldValue, ply); - return true; + stp = stp->previous->previous; + perpetual &= bool(stp->checkersBB); + + // Return a draw score if a position repeats once earlier but strictly + // after the root, or repeats twice before or at the root. + if ( stp->key == st->key + && ++cnt + 1 == (ply > i ? 2 : n_fold_rule())) + { + result = convert_mate_value( var->perpetualCheckIllegal && perpetual ? VALUE_MATE + : var->nFoldValueAbsolute && sideToMove == BLACK ? -var->nFoldValue + : var->nFoldValue, ply); + return true; + } } } }