summaryrefslogtreecommitdiff
path: root/Userland/Services
diff options
context:
space:
mode:
authorTim Ledbetter <timledbetter@gmail.com>2023-04-01 23:18:10 +0100
committerSam Atkins <atkinssj@gmail.com>2023-04-20 09:59:18 +0100
commitc2b9376409fe06f8ca3bb03d39a793a3e78c7c1e (patch)
treeef50f12135685da1acb759d27b202754e4df4729 /Userland/Services
parent13dbc69c23ddeab40eedb0e0edf93fc8e699b6e6 (diff)
downloadserenity-c2b9376409fe06f8ca3bb03d39a793a3e78c7c1e.zip
ChessEngine: Handle the UCI quit command
Diffstat (limited to 'Userland/Services')
-rw-r--r--Userland/Services/ChessEngine/ChessEngine.cpp6
-rw-r--r--Userland/Services/ChessEngine/ChessEngine.h3
-rw-r--r--Userland/Services/ChessEngine/main.cpp4
3 files changed, 13 insertions, 0 deletions
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<void(int)> 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<int> 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();
}