X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fposition.cpp;h=310e46e36190704121571efff452399bf53911a9;hp=4045a25d96f454182b9de283b593d0b0d48c53c1;hb=58c9fbacc787cc3b654244c071169057e6895c91;hpb=483c98a69e8c6836c655d92a150d70fbe780341f diff --git a/src/position.cpp b/src/position.cpp index 4045a25d..310e46e3 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -1363,31 +1363,36 @@ 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. -template +template bool Position::is_draw() const { + // Draw by material? 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(*this).size())) return true; - if (CheckRepetition) + // Draw by repetition? + if (!SkipRepetition) { - int i = 4, e = std::min(st->rule50, st->pliesFromNull), cnt; + int i = 4, e = std::min(st->rule50, st->pliesFromNull); if (i <= e) { StateInfo* stp = st->previous->previous; - for (cnt = 0; i <= e; i += 2) - { + do { stp = stp->previous->previous; - if (stp->key == st->key && (!CheckThreeFold || ++cnt >= 2)) + if (stp->key == st->key) return true; - } + + i += 2; + + } while (i <= e); } } @@ -1395,9 +1400,8 @@ bool Position::is_draw() const { } // Explicit template instantiations -template bool Position::is_draw() const; -template bool Position::is_draw() const; -template bool Position::is_draw() const; +template bool Position::is_draw() const; +template bool Position::is_draw() const; /// Position::flip() flips position with the white and black sides reversed. This