From effab83b44a6cfd298967af21c8f13b29c1b5771 Mon Sep 17 00:00:00 2001 From: Calcitem Date: Wed, 13 Jan 2021 01:15:11 +0800 Subject: [PATCH] rule50: Detect rule50 when searching --- src/position.cpp | 17 ++++++++++++----- src/search.cpp | 10 ++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/position.cpp b/src/position.cpp index b2dbb06a..76dc7c91 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -405,15 +405,24 @@ void Position::do_move(Move m) switch (mt) { case MOVETYPE_REMOVE: - // Reset rule 50 counter - st.rule50 = 0; ret = remove_piece(to_sq(m)); + if (ret) { + // Reset rule 50 counter + st.rule50 = 0; + } break; case MOVETYPE_MOVE: ret = move_piece(from_sq(m), to_sq(m)); + if (ret) { + ++st.rule50; + } break; case MOVETYPE_PLACE: ret = put_piece(to_sq(m)); + if (ret) { + // Reset rule 50 counter + st.rule50 = 0; + } break; default: break; @@ -423,10 +432,8 @@ void Position::do_move(Move m) return; } - // Increment ply counters. In particular, rule50 will be reset to zero later on - // in case of a remove. + // Increment ply counters. In particular ++gamePly; - ++st.rule50; ++st.pliesFromNull; move = m; diff --git a/src/search.cpp b/src/search.cpp index 763bc2bd..746d7f87 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -111,6 +111,9 @@ int Thread::search() if (rootPos->get_phase() == Phase::placing) { posKeyHistory.clear(); + rootPos->st.rule50 = 0; + } else if (rootPos->get_phase() == Phase::moving) { + rootPos->st.rule50 = (int)posKeyHistory.size(); } @@ -201,6 +204,13 @@ Value search(Position *pos, Sanmill::Stack &ss, Depth depth, Depth ori Depth epsilon; + if (pos->rule50_count() > 99) { + alpha = VALUE_DRAW; + if (alpha >= beta) { + return alpha; + } + } + #ifdef THREEFOLD_REPETITION // Check if we have an upcoming move which draws by repetition, or // if the opponent had an alternative move earlier to this position.