From: Marco Costalba Date: Tue, 3 Dec 2013 10:37:29 +0000 (+0100) Subject: Shrink Position::is_draw() X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=2408243cf41ad7dfbd678c4d08756b17c342defc Shrink Position::is_draw() No functional change. --- diff --git a/src/position.cpp b/src/position.cpp index 6088477d..3b59b24a 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -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 { - // 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; - 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;