Skip to content

Commit 66372b6

Browse files
authored
fix: indefinite wait for bestmove after time loss (#237)
1 parent 111e3c4 commit 66372b6

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

src/engines/uci_engine.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,13 @@ int UciEngine::lastScore() const {
145145
return str_utils::findElement<int>(lastInfo(), lastScoreType() == ScoreType::CP ? "cp" : "mate")
146146
.value_or(0);
147147
}
148+
149+
bool UciEngine::outputIncludesBestmove() const {
150+
for (const auto &line : output_) {
151+
if (line.find("bestmove") != std::string::npos) return true;
152+
}
153+
154+
return false;
155+
}
156+
148157
} // namespace fast_chess

src/engines/uci_engine.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ class UciEngine : Process {
7272
/// @return
7373
[[nodiscard]] int lastScore() const;
7474

75+
[[nodiscard]] bool outputIncludesBestmove() const;
76+
7577
[[nodiscard]] const std::vector<std::string> &output() const noexcept { return output_; }
7678
[[nodiscard]] const EngineConfiguration &getConfig() const noexcept { return config_; }
7779

src/matchmaking/match/match.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,10 @@ bool Match::playMove(Player& us, Player& opponent) {
193193

194194
us.engine.writeEngine("stop");
195195

196-
// wait for bestmove, indefinitely
197-
us.engine.readEngine("bestmove", 0ms);
196+
if (!us.engine.outputIncludesBestmove()) {
197+
// wait for bestmove, indefinitely
198+
us.engine.readEngine("bestmove", 0ms);
199+
}
198200

199201
return false;
200202
}

0 commit comments

Comments
 (0)