From 13dbc69c23ddeab40eedb0e0edf93fc8e699b6e6 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Sat, 1 Apr 2023 23:15:53 +0100 Subject: LibChess: Add the UCI quit command --- Userland/Libraries/LibChess/UCICommand.cpp | 13 +++++++++++++ Userland/Libraries/LibChess/UCICommand.h | 12 ++++++++++++ Userland/Libraries/LibChess/UCIEndpoint.cpp | 4 ++++ Userland/Libraries/LibChess/UCIEndpoint.h | 1 + 4 files changed, 30 insertions(+) diff --git a/Userland/Libraries/LibChess/UCICommand.cpp b/Userland/Libraries/LibChess/UCICommand.cpp index a53d7367d8..94799b30fa 100644 --- a/Userland/Libraries/LibChess/UCICommand.cpp +++ b/Userland/Libraries/LibChess/UCICommand.cpp @@ -333,4 +333,17 @@ DeprecatedString InfoCommand::to_deprecated_string() const return "info"; } +QuitCommand QuitCommand::from_string([[maybe_unused]] StringView command) +{ + auto tokens = command.split_view(' '); + VERIFY(tokens[0] == "quit"); + VERIFY(tokens.size() == 1); + return QuitCommand(); +} + +DeprecatedString QuitCommand::to_deprecated_string() const +{ + return "quit\n"; +} + } diff --git a/Userland/Libraries/LibChess/UCICommand.h b/Userland/Libraries/LibChess/UCICommand.h index f75d22308c..c910fcf04f 100644 --- a/Userland/Libraries/LibChess/UCICommand.h +++ b/Userland/Libraries/LibChess/UCICommand.h @@ -268,4 +268,16 @@ public: // FIXME: Add additional fields. }; +class QuitCommand : public Command { +public: + explicit QuitCommand() + : Command(Command::Type::Quit) + { + } + + static QuitCommand from_string(StringView command); + + virtual DeprecatedString to_deprecated_string() const override; +}; + } diff --git a/Userland/Libraries/LibChess/UCIEndpoint.cpp b/Userland/Libraries/LibChess/UCIEndpoint.cpp index fad07d619e..7693d0e3df 100644 --- a/Userland/Libraries/LibChess/UCIEndpoint.cpp +++ b/Userland/Libraries/LibChess/UCIEndpoint.cpp @@ -53,6 +53,8 @@ void Endpoint::event(Core::Event& event) return handle_bestmove(static_cast(event)); case Command::Type::Info: return handle_info(static_cast(event)); + case Command::Type::Quit: + return handle_quit(); default: break; } @@ -97,6 +99,8 @@ NonnullOwnPtr Endpoint::read_command() return make(BestMoveCommand::from_string(line)); } else if (line.starts_with("info"sv)) { return make(InfoCommand::from_string(line)); + } else if (line.starts_with("quit"sv)) { + return make(QuitCommand::from_string(line)); } dbgln("command line: {}", line); diff --git a/Userland/Libraries/LibChess/UCIEndpoint.h b/Userland/Libraries/LibChess/UCIEndpoint.h index 8e99ab979d..00ae61ef39 100644 --- a/Userland/Libraries/LibChess/UCIEndpoint.h +++ b/Userland/Libraries/LibChess/UCIEndpoint.h @@ -30,6 +30,7 @@ public: virtual void handle_readyok() { } virtual void handle_bestmove(BestMoveCommand const&) { } virtual void handle_info(InfoCommand const&) { } + virtual void handle_quit() { } void send_command(Command const&); -- cgit v1.2.3