From 27d19462497e89249ccb8dc28010d7dcb3e25fe2 Mon Sep 17 00:00:00 2001 From: Fabian Fichter Date: Sun, 14 Jun 2020 14:52:25 +0200 Subject: [PATCH] Adjudicate optional game ends in CECP protocol Closes #150. --- src/position.h | 10 ++++++++-- src/search.cpp | 6 +++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/position.h b/src/position.h index 12df6c1..a0ca7cb 100644 --- a/src/position.h +++ b/src/position.h @@ -253,9 +253,10 @@ public: bool is_chess960() const; Thread* this_thread() const; bool is_immediate_game_end() const; - bool is_game_end(Value& result, int ply = 0) const; - bool is_optional_game_end(Value& result, int ply = 0, int countStarted = 0) const; bool is_immediate_game_end(Value& result, int ply = 0) const; + bool is_optional_game_end() const; + bool is_optional_game_end(Value& result, int ply = 0, int countStarted = 0) const; + bool is_game_end(Value& result, int ply = 0) const; Value material_counting_result() const; bool has_game_cycle(int ply) const; bool has_repeated() const; @@ -729,6 +730,11 @@ inline bool Position::is_immediate_game_end() const { return is_immediate_game_end(result); } +inline bool Position::is_optional_game_end() const { + Value result; + return is_optional_game_end(result); +} + inline bool Position::is_game_end(Value& result, int ply) const { return is_immediate_game_end(result, ply) || is_optional_game_end(result, ply); } diff --git a/src/search.cpp b/src/search.cpp index a2f4640..7629f9e 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -229,7 +229,7 @@ void MainThread::search() { Time.init(rootPos, Limits, us, rootPos.game_ply()); TT.new_search(); - if (rootMoves.empty()) + if (rootMoves.empty() || (Options["Protocol"] == "xboard" && rootPos.is_optional_game_end())) { rootMoves.emplace_back(MOVE_NONE); Value variantResult; @@ -237,10 +237,14 @@ void MainThread::search() { : rootPos.checkers() ? rootPos.checkmate_value() : rootPos.stalemate_value(); if (Options["Protocol"] == "xboard") + { + // rotate MOVE_NONE to front (for optional game end) + std::rotate(rootMoves.rbegin(), rootMoves.rbegin() + 1, rootMoves.rend()); sync_cout << ( result == VALUE_DRAW ? "1/2-1/2 {Draw}" : (rootPos.side_to_move() == BLACK ? -result : result) == VALUE_MATE ? "1-0 {White wins}" : "0-1 {Black wins}") << sync_endl; + } else sync_cout << "info depth 0 score " << UCI::value(result) -- 1.7.0.4