mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 21:07:34 +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:
parent
7e6341587b
commit
18735960de
4 changed files with 30 additions and 0 deletions
|
@ -348,4 +348,17 @@ ErrorOr<String> QuitCommand::to_string() const
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -281,4 +281,16 @@ public:
|
|||
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;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -56,6 +56,8 @@ void Endpoint::event(Core::Event& event)
|
|||
return handle_info(static_cast<InfoCommand const&>(event));
|
||||
case Command::Type::Quit:
|
||||
return handle_quit();
|
||||
case Command::Type::UCINewGame:
|
||||
return handle_ucinewgame();
|
||||
default:
|
||||
Object::event(event);
|
||||
break;
|
||||
|
@ -115,6 +117,8 @@ NonnullOwnPtr<Command> Endpoint::read_command()
|
|||
return InfoCommand::from_string(line).release_value_but_fixme_should_propagate_errors();
|
||||
} else if (line.starts_with("quit"sv)) {
|
||||
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);
|
||||
|
|
|
@ -31,6 +31,7 @@ public:
|
|||
virtual void handle_bestmove(BestMoveCommand const&) { }
|
||||
virtual void handle_info(InfoCommand const&) { }
|
||||
virtual void handle_quit() { }
|
||||
virtual void handle_ucinewgame() { }
|
||||
virtual void handle_unexpected_eof() { }
|
||||
|
||||
void send_command(Command const&);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue