From bf320e4826ece33b0190332dda3e135786b48c89 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Sat, 1 Apr 2023 23:23:43 +0100 Subject: [PATCH] Chess: Send a quit command to ChessEngine when it is no longer in use The chess GUI now instructs the ChessEngine to gracefully exit by sending a UCI quit command. --- Userland/Games/Chess/Engine.cpp | 8 ++++++-- Userland/Games/Chess/Engine.h | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Userland/Games/Chess/Engine.cpp b/Userland/Games/Chess/Engine.cpp index a28b5fc13c..cbfcf40d1d 100644 --- a/Userland/Games/Chess/Engine.cpp +++ b/Userland/Games/Chess/Engine.cpp @@ -13,8 +13,7 @@ Engine::~Engine() { - if (m_pid != -1) - kill(m_pid, SIGINT); + quit(); } Engine::Engine(StringView command) @@ -66,3 +65,8 @@ void Engine::handle_bestmove(Chess::UCI::BestMoveCommand const& command) m_bestmove_callback = nullptr; } + +void Engine::quit() +{ + send_command(Chess::UCI::QuitCommand()); +} diff --git a/Userland/Games/Chess/Engine.h b/Userland/Games/Chess/Engine.h index d91127714b..dd5906cf84 100644 --- a/Userland/Games/Chess/Engine.h +++ b/Userland/Games/Chess/Engine.h @@ -33,6 +33,7 @@ public: } private: + void quit(); + Function m_bestmove_callback; - pid_t m_pid { -1 }; };