From eda027f9750f73d303aee3fd8a9012ee843a5ea9 Mon Sep 17 00:00:00 2001 From: Calcitem Date: Sat, 28 Nov 2020 00:00:38 +0800 Subject: [PATCH] =?UTF-8?q?position:=20=E8=A7=A3=E5=86=B3=E7=89=B9?= =?UTF-8?q?=E5=AE=9A=E6=9D=A1=E4=BB=B6=E4=B8=8B=E6=AF=8F3=E6=AC=A1go?= =?UTF-8?q?=E5=87=BA=E7=8E=B01=E4=B8=AA=20draw=20=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit nRepetition 由静态变量改为全局变量 用例: position fen O@@OOOO@/OOO**@O@/@O@@O@@O b m p 10 0 12 0 0 2 14 moves (3,4)->(2,4) (3,5)->(3,4) (2,4)->(2,5) --- src/position.cpp | 8 ++++++++ src/search.cpp | 5 +++-- src/uci.cpp | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/position.cpp b/src/position.cpp index 616e7505..6fa7d45e 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -744,8 +744,16 @@ int Position::set_position(const struct Rule *newRule) return -1; } +#ifdef THREEFOLD_REPETITION +extern int nRepetition; +#endif // THREEFOLD_REPETITION + bool Position::reset() { +#ifdef THREEFOLD_REPETITION + nRepetition = 0; +#endif // THREEFOLD_REPETITION + gamePly = 0; st.rule50 = 0; diff --git a/src/search.cpp b/src/search.cpp index d0ec859c..263c746d 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -78,6 +78,9 @@ void Search::clear() Threads.clear(); } +#ifdef THREEFOLD_REPETITION +int nRepetition; +#endif // THREEFOLD_REPETITION /// Thread::search() is the main iterative deepening loop. It calls search() /// repeatedly with increasing depth until the allocated thinking time has been @@ -105,8 +108,6 @@ int Thread::search() #endif #ifdef THREEFOLD_REPETITION - static int nRepetition = 0; - if (rootPos->get_phase() == PHASE_MOVING) { Key key = rootPos->key(); diff --git a/src/uci.cpp b/src/uci.cpp index 1bdd3834..a81c22dc 100644 --- a/src/uci.cpp +++ b/src/uci.cpp @@ -41,6 +41,11 @@ using namespace std; extern vector setup_bench(Position *, istream &); +#ifdef THREEFOLD_REPETITION +extern int nRepetition; +extern vector moveHistory; +#endif // THREEFOLD_REPETITION + namespace { @@ -69,11 +74,19 @@ void position(Position *pos, istringstream &is) else return; +#ifdef THREEFOLD_REPETITION + nRepetition = 0; + moveHistory.clear(); +#endif // THREEFOLD_REPETITION + pos->set(fen, Threads.main()); // Parse move list (if any) while (is >> token && (m = UCI::to_move(pos, token)) != MOVE_NONE) { pos->do_move(m); +#ifdef THREEFOLD_REPETITION + moveHistory.push_back(pos->key()); +#endif // THREEFOLD_REPETITION } Threads.main()->us = pos->sideToMove; @@ -113,6 +126,11 @@ void go(Position *pos) #ifdef UCI_AUTO_RE_GO begin: #endif + +#ifdef THREEFOLD_REPETITION + nRepetition = 0; +#endif // THREEFOLD_REPETITION + Threads.start_thinking(pos); if (pos->get_phase() == PHASE_GAMEOVER)