From 797602938da5087d0af2448a72767cb17cd8c248 Mon Sep 17 00:00:00 2001 From: Aram Tumanian Date: Fri, 11 Nov 2016 17:46:21 +0200 Subject: [PATCH] Start searching for a repetition from the 4th ply behind A position can never repeat the one on the previous move. Thus we can start searching for a repetition from the 4th ply behind. In the case: std::min(st->rule50, st->pliesFromNull) < 4 We don't need to do any more calculations. This case happens very often - in more than a half of all calls of the function. No functional change. --- src/position.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/position.cpp b/src/position.cpp index 325ffd11..fd518488 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -1079,14 +1079,20 @@ bool Position::is_draw() const { if (st->rule50 > 99 && (!checkers() || MoveList(*this).size())) return true; - StateInfo* stp = st; - for (int i = 2, e = std::min(st->rule50, st->pliesFromNull); i <= e; i += 2) - { + int e = std::min(st->rule50, st->pliesFromNull); + + if (e < 4) + return false; + + StateInfo* stp = st->previous->previous; + + do { stp = stp->previous->previous; if (stp->key == st->key) return true; // Draw at first repetition - } + + } while ((e -= 2) >= 4); return false; } -- 2.39.2