]> git.sesse.net Git - stockfish/blobdiff - src/search.cpp
Detect repetitions before they happen in qsearch
[stockfish] / src / search.cpp
index 03d72b95373b412a543cf72641893817c5351348..44e13dae8d386f74a8a95f6aa4436b5c3b09d15a 100644 (file)
@@ -1410,6 +1410,18 @@ moves_loop: // When in check, search starts here
     assert(PvNode || (alpha == beta - 1));
     assert(depth <= 0);
 
+    // Check if we have an upcoming move that draws by repetition, or
+    // if the opponent had an alternative move earlier to this position.
+    if (   depth < 0
+        && pos.rule50_count() >= 3
+        && alpha < VALUE_DRAW
+        && pos.has_game_cycle(ss->ply))
+    {
+        alpha = value_draw(pos.this_thread());
+        if (alpha >= beta)
+            return alpha;
+    }
+
     Move pv[MAX_PLY+1];
     StateInfo st;
     ASSERT_ALIGNED(&st, Eval::NNUE::CacheLineSize);