mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 04:47:35 +00:00
Chess: Gracefully handle ChessEngine disconnections
The GUI now tracks when it becomes disconnected from ChessEngine. If not currently waiting for a move from ChessEngine, it will automatically reconnect on the next engine move. If a disconnection occurs while waiting for a move, the player is asked whether they want to try again or not.
This commit is contained in:
parent
55347ed6a5
commit
8b6c538f2a
4 changed files with 63 additions and 20 deletions
|
@ -20,11 +20,17 @@ public:
|
|||
Engine(Engine const&) = delete;
|
||||
Engine& operator=(Engine const&) = delete;
|
||||
|
||||
Function<void()> on_connection_lost;
|
||||
|
||||
virtual void handle_bestmove(Chess::UCI::BestMoveCommand const&) override;
|
||||
virtual void handle_unexpected_eof() override;
|
||||
|
||||
template<typename Callback>
|
||||
void get_best_move(Chess::Board const& board, int time_limit, Callback&& callback)
|
||||
{
|
||||
if (!m_connected)
|
||||
connect_to_engine_service();
|
||||
|
||||
send_command(Chess::UCI::PositionCommand({}, board.moves()));
|
||||
Chess::UCI::GoCommand go_command;
|
||||
go_command.movetime = time_limit;
|
||||
|
@ -34,6 +40,9 @@ public:
|
|||
|
||||
private:
|
||||
void quit();
|
||||
void connect_to_engine_service();
|
||||
|
||||
Function<void(Chess::Move)> m_bestmove_callback;
|
||||
DeprecatedString m_command;
|
||||
Function<void(ErrorOr<Chess::Move>)> m_bestmove_callback;
|
||||
bool m_connected { false };
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue