From c55ae376f62de80fd20822954aaa6c7cd23eb2fa Mon Sep 17 00:00:00 2001 From: Disservin Date: Sat, 13 Apr 2024 21:54:10 +0200 Subject: [PATCH] Fix wrong sign for 200 TB score Fix another case of 9032c6cbe74ccf7e8963755501e7e6cc473ae471 * TB values can have a distance of 0, mainly when we are in a tb position but haven't found mate. * Add a missing whitespace to UCIEngine::on_update_no_moves() Closes https://github.com/official-stockfish/Stockfish/pull/5172 No functional change --- src/score.cpp | 2 +- src/score.h | 7 ++++--- src/uci.cpp | 6 +++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/score.cpp b/src/score.cpp index d1a8a6abe4d..292f53406e2 100644 --- a/src/score.cpp +++ b/src/score.cpp @@ -36,7 +36,7 @@ Score::Score(Value v, const Position& pos) { else if (std::abs(v) <= VALUE_TB) { auto distance = VALUE_TB - std::abs(v); - score = (v > 0) ? TBWin{distance} : TBWin{-distance}; + score = (v > 0) ? Tablebase{distance, true} : Tablebase{-distance, false}; } else { diff --git a/src/score.h b/src/score.h index b94d9f7fb6b..2eb40f7e08e 100644 --- a/src/score.h +++ b/src/score.h @@ -34,8 +34,9 @@ class Score { int plies; }; - struct TBWin { - int plies; + struct Tablebase { + int plies; + bool win; }; struct InternalUnits { @@ -61,7 +62,7 @@ class Score { } private: - std::variant score; + std::variant score; }; } diff --git a/src/uci.cpp b/src/uci.cpp index 8f697836913..8e20207b79e 100644 --- a/src/uci.cpp +++ b/src/uci.cpp @@ -357,9 +357,9 @@ std::string UCIEngine::format_score(const Score& s) { auto m = (mate.plies > 0 ? (mate.plies + 1) : mate.plies) / 2; return std::string("mate ") + std::to_string(m); }, - [](Score::TBWin tb) -> std::string { + [](Score::Tablebase tb) -> std::string { return std::string("cp ") - + std::to_string((tb.plies > 0 ? TB_CP - tb.plies : -TB_CP - tb.plies)); + + std::to_string((tb.win ? TB_CP - tb.plies : -TB_CP - tb.plies)); }, [](Score::InternalUnits units) -> std::string { return std::string("cp ") + std::to_string(units.value); @@ -435,7 +435,7 @@ Move UCIEngine::to_move(const Position& pos, std::string str) { } void UCIEngine::on_update_no_moves(const Engine::InfoShort& info) { - sync_cout << "info depth" << info.depth << " score " << format_score(info.score) << sync_endl; + sync_cout << "info depth " << info.depth << " score " << format_score(info.score) << sync_endl; } void UCIEngine::on_update_full(const Engine::InfoFull& info, bool showWDL) {