summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Ledbetter <timledbetter@gmail.com>2023-04-01 23:15:53 +0100
committerSam Atkins <atkinssj@gmail.com>2023-04-20 09:59:18 +0100
commit13dbc69c23ddeab40eedb0e0edf93fc8e699b6e6 (patch)
tree77f9160cd269764d2086a2387a55c58364026ea4
parentd2f9645cc00be122625298a7d7ddbb36bb5ba3aa (diff)
downloadserenity-13dbc69c23ddeab40eedb0e0edf93fc8e699b6e6.zip
LibChess: Add the UCI quit command
-rw-r--r--Userland/Libraries/LibChess/UCICommand.cpp13
-rw-r--r--Userland/Libraries/LibChess/UCICommand.h12
-rw-r--r--Userland/Libraries/LibChess/UCIEndpoint.cpp4
-rw-r--r--Userland/Libraries/LibChess/UCIEndpoint.h1
4 files changed, 30 insertions, 0 deletions
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<BestMoveCommand const&>(event));
case Command::Type::Info:
return handle_info(static_cast<InfoCommand const&>(event));
+ case Command::Type::Quit:
+ return handle_quit();
default:
break;
}
@@ -97,6 +99,8 @@ NonnullOwnPtr<Command> Endpoint::read_command()
return make<BestMoveCommand>(BestMoveCommand::from_string(line));
} else if (line.starts_with("info"sv)) {
return make<InfoCommand>(InfoCommand::from_string(line));
+ } else if (line.starts_with("quit"sv)) {
+ return make<QuitCommand>(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&);