diff --git a/Userland/Services/ChessEngine/ChessEngine.cpp b/Userland/Services/ChessEngine/ChessEngine.cpp index 15a8040a62..a5395cb906 100644 --- a/Userland/Services/ChessEngine/ChessEngine.cpp +++ b/Userland/Services/ChessEngine/ChessEngine.cpp @@ -62,3 +62,9 @@ void ChessEngine::handle_go(GoCommand const& command) m_last_tree = move(best_node); } + +void ChessEngine::handle_quit() +{ + if (on_quit) + on_quit(ESUCCESS); +} diff --git a/Userland/Services/ChessEngine/ChessEngine.h b/Userland/Services/ChessEngine/ChessEngine.h index cf2d2a2e49..37ae88603b 100644 --- a/Userland/Services/ChessEngine/ChessEngine.h +++ b/Userland/Services/ChessEngine/ChessEngine.h @@ -18,6 +18,9 @@ public: virtual void handle_uci() override; virtual void handle_position(Chess::UCI::PositionCommand const&) override; virtual void handle_go(Chess::UCI::GoCommand const&) override; + virtual void handle_quit() override; + + Function on_quit; private: ChessEngine() = default; diff --git a/Userland/Services/ChessEngine/main.cpp b/Userland/Services/ChessEngine/main.cpp index a16ca4e8a2..ddc7058ed0 100644 --- a/Userland/Services/ChessEngine/main.cpp +++ b/Userland/Services/ChessEngine/main.cpp @@ -17,5 +17,9 @@ ErrorOr serenity_main(Main::Arguments) TRY(Core::System::unveil(nullptr, nullptr)); auto engine = TRY(ChessEngine::try_create(Core::DeprecatedFile::standard_input(), Core::DeprecatedFile::standard_output())); + engine->on_quit = [&](auto status_code) { + loop.quit(status_code); + }; + return loop.exec(); }