From 0587c5b605fc9f0c23dab3a890b2986276c259cb Mon Sep 17 00:00:00 2001 From: Jean-Francois Romang Date: Tue, 23 Oct 2012 20:33:45 +0000 Subject: [PATCH] Allow full repetition detection Based on sshivaji 6ee19aa5389ce60181907ba53bbb50642f2d5657 commit --- src/position.cpp | 14 +++++++++----- src/position.h | 2 +- src/search.cpp | 6 +++--- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/position.cpp b/src/position.cpp index 3f819946..feaeee22 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -1467,7 +1467,7 @@ 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? @@ -1482,7 +1482,7 @@ bool Position::is_draw() const { // Draw by repetition? if (!SkipRepetition) { - int i = 4, e = std::min(st->rule50, st->pliesFromNull); + int i = 4, e = std::min(st->rule50, st->pliesFromNull), rep_count=0; if (i <= e) { @@ -1492,7 +1492,10 @@ bool Position::is_draw() const { stp = stp->previous->previous; if (stp->key == st->key) - return true; + { + if(SkipThreeFoldCheck) return true; + else if(++rep_count>=2) return true; + } i +=2; @@ -1504,8 +1507,9 @@ 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 diff --git a/src/position.h b/src/position.h index fced8e0c..ce636fe3 100644 --- a/src/position.h +++ b/src/position.h @@ -183,7 +183,7 @@ public: Thread* this_thread() const; int64_t nodes_searched() const; void set_nodes_searched(int64_t n); - template bool is_draw() const; + template bool is_draw() const; // Position consistency check, for debugging bool pos_is_ok(int* failedStep = NULL) const; diff --git a/src/search.cpp b/src/search.cpp index 4ac94402..54523631 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -524,7 +524,7 @@ namespace { if (!RootNode) { // Step 2. Check for aborted search and immediate draw - if (Signals.stop || pos.is_draw() || ss->ply > MAX_PLY) + if (Signals.stop || pos.is_draw() || ss->ply > MAX_PLY) return DrawValue[pos.side_to_move()]; // Step 3. Mate distance pruning. Even if we mate at the next move our score @@ -1103,7 +1103,7 @@ split_point_start: // At split points actual search starts from here ss->ply = (ss-1)->ply + 1; // Check for an instant draw or maximum ply reached - if (pos.is_draw() || ss->ply > MAX_PLY) + if (pos.is_draw() || ss->ply > MAX_PLY) return DrawValue[pos.side_to_move()]; // Transposition table lookup. At PV nodes, we don't use the TT for @@ -1552,7 +1552,7 @@ void RootMove::extract_pv_from_tt(Position& pos) { && pos.is_pseudo_legal(m) && pos.pl_move_is_legal(m, pos.pinned_pieces()) && ply < MAX_PLY - && (!pos.is_draw() || ply < 2)) + && (!pos.is_draw() || ply < 2)) { pv.push_back(m); pos.do_move(m, *st++); -- 2.39.2