From 285cee07ef86dff5b6580f84529cbc282042c48b Mon Sep 17 00:00:00 2001 From: Calcitem Date: Tue, 12 Jan 2021 01:07:29 +0800 Subject: [PATCH] rule50: Judge rule50 and draw (WIP) --- src/position.cpp | 2 +- src/search.cpp | 3 +++ src/thread.cpp | 4 +++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/position.cpp b/src/position.cpp index 7441cf99..b2dbb06a 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -935,7 +935,7 @@ bool Position::check_if_game_is_over() } if (rule.maxStepsLedToDraw > 0 && - rule50_count() > rule.maxStepsLedToDraw) { + posKeyHistory.size() > rule.maxStepsLedToDraw) { winner = DRAW; phase = Phase::gameOver; gameOverReason = GameOverReason::drawReasonRule50; diff --git a/src/search.cpp b/src/search.cpp index 7f0c822e..59c768e7 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -93,6 +93,9 @@ int Thread::search() #endif if (rootPos->get_phase() == Phase::moving) { + if (posKeyHistory.size() > rule.maxStepsLedToDraw) { + return 99; + } #ifdef THREEFOLD_REPETITION if (rootPos->has_game_cycle()) { return 3; diff --git a/src/thread.cpp b/src/thread.cpp index 36a3a7f3..fb26552c 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -143,7 +143,9 @@ void Thread::idle_loop() emitCommand(); } else { #endif - if (search() == 3) { + int ret = search(); + + if (ret == 3 || ret == 50) { loggerDebug("Draw\n\n"); strCommand = "draw"; emitCommand();