1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 06:27:45 +00:00

LibChess: Add the ucinewgame command

This command is sent from the GUI to tell the engine that the next
position will be from a different game.
This commit is contained in:
Tim Ledbetter 2023-04-26 19:00:48 +01:00 committed by Andreas Kling
parent 7e6341587b
commit 18735960de
4 changed files with 30 additions and 0 deletions

View file

@ -348,4 +348,17 @@ ErrorOr<String> QuitCommand::to_string() const
return "quit\n"_short_string; return "quit\n"_short_string;
} }
ErrorOr<NonnullOwnPtr<UCINewGameCommand>> UCINewGameCommand::from_string(StringView command)
{
auto tokens = command.split_view(' ');
VERIFY(tokens[0] == "ucinewgame");
VERIFY(tokens.size() == 1);
return adopt_nonnull_own_or_enomem(new (nothrow) UCINewGameCommand);
}
ErrorOr<String> UCINewGameCommand::to_string() const
{
return "ucinewgame\n"_string;
}
} }

View file

@ -281,4 +281,16 @@ public:
virtual ErrorOr<String> to_string() const override; virtual ErrorOr<String> to_string() const override;
}; };
class UCINewGameCommand : public Command {
public:
explicit UCINewGameCommand()
: Command(Command::Type::UCINewGame)
{
}
static ErrorOr<NonnullOwnPtr<UCINewGameCommand>> from_string(StringView command);
virtual ErrorOr<String> to_string() const override;
};
} }

View file

@ -56,6 +56,8 @@ void Endpoint::event(Core::Event& event)
return handle_info(static_cast<InfoCommand const&>(event)); return handle_info(static_cast<InfoCommand const&>(event));
case Command::Type::Quit: case Command::Type::Quit:
return handle_quit(); return handle_quit();
case Command::Type::UCINewGame:
return handle_ucinewgame();
default: default:
Object::event(event); Object::event(event);
break; break;
@ -115,6 +117,8 @@ NonnullOwnPtr<Command> Endpoint::read_command()
return InfoCommand::from_string(line).release_value_but_fixme_should_propagate_errors(); return InfoCommand::from_string(line).release_value_but_fixme_should_propagate_errors();
} else if (line.starts_with("quit"sv)) { } else if (line.starts_with("quit"sv)) {
return QuitCommand::from_string(line).release_value_but_fixme_should_propagate_errors(); return QuitCommand::from_string(line).release_value_but_fixme_should_propagate_errors();
} else if (line.starts_with("ucinewgame"sv)) {
return UCINewGameCommand::from_string(line).release_value_but_fixme_should_propagate_errors();
} }
dbgln("command line: {}", line); dbgln("command line: {}", line);

View file

@ -31,6 +31,7 @@ public:
virtual void handle_bestmove(BestMoveCommand const&) { } virtual void handle_bestmove(BestMoveCommand const&) { }
virtual void handle_info(InfoCommand const&) { } virtual void handle_info(InfoCommand const&) { }
virtual void handle_quit() { } virtual void handle_quit() { }
virtual void handle_ucinewgame() { }
virtual void handle_unexpected_eof() { } virtual void handle_unexpected_eof() { }
void send_command(Command const&); void send_command(Command const&);