diff options
author | Tim Ledbetter <timledbetter@gmail.com> | 2023-04-24 12:17:56 +0100 |
---|---|---|
committer | Sam Atkins <atkinssj@gmail.com> | 2023-05-03 08:31:34 +0100 |
commit | 25778d07e986b512aaa87a622cd6efb918b342dc (patch) | |
tree | efd0a9c91b850e0ff835afadac5ce9b9f957540d /Userland/Libraries/LibChess | |
parent | c885df98da42a9de814aecbf5c0e341b6213e670 (diff) | |
download | serenity-25778d07e986b512aaa87a622cd6efb918b342dc.zip |
LibChess: Add optional ponder move to the BestMove command
The BestMove command can now include an optional ponder token, with
the move that the engine would like to ponder on.
Diffstat (limited to 'Userland/Libraries/LibChess')
-rw-r--r-- | Userland/Libraries/LibChess/UCICommand.cpp | 15 | ||||
-rw-r--r-- | Userland/Libraries/LibChess/UCICommand.h | 5 |
2 files changed, 17 insertions, 3 deletions
diff --git a/Userland/Libraries/LibChess/UCICommand.cpp b/Userland/Libraries/LibChess/UCICommand.cpp index 90a84dd9e5..c849a17140 100644 --- a/Userland/Libraries/LibChess/UCICommand.cpp +++ b/Userland/Libraries/LibChess/UCICommand.cpp @@ -311,8 +311,15 @@ ErrorOr<NonnullOwnPtr<BestMoveCommand>> BestMoveCommand::from_string(StringView { auto tokens = command.split_view(' '); VERIFY(tokens[0] == "bestmove"); - VERIFY(tokens.size() == 2); - return adopt_nonnull_own_or_enomem(new (nothrow) BestMoveCommand(Move(tokens[1]))); + VERIFY(tokens.size() == 2 || tokens.size() == 4); + auto best_move = Move(tokens[1]); + Optional<Move> move_to_ponder; + if (tokens.size() == 4) { + VERIFY(tokens[2] == "ponder"); + move_to_ponder = Move(tokens[3]); + } + + return adopt_nonnull_own_or_enomem(new (nothrow) BestMoveCommand(best_move, move_to_ponder)); } ErrorOr<String> BestMoveCommand::to_string() const @@ -320,6 +327,10 @@ ErrorOr<String> BestMoveCommand::to_string() const StringBuilder builder; TRY(builder.try_append("bestmove "sv)); TRY(builder.try_append(TRY(move().to_long_algebraic()))); + if (move_to_ponder().has_value()) { + TRY(builder.try_append(" ponder "sv)); + TRY(builder.try_append(TRY(move_to_ponder()->to_long_algebraic()))); + } TRY(builder.try_append('\n')); return builder.to_string(); } diff --git a/Userland/Libraries/LibChess/UCICommand.h b/Userland/Libraries/LibChess/UCICommand.h index 318fb58f2c..217f955433 100644 --- a/Userland/Libraries/LibChess/UCICommand.h +++ b/Userland/Libraries/LibChess/UCICommand.h @@ -229,9 +229,10 @@ public: class BestMoveCommand : public Command { public: - explicit BestMoveCommand(Chess::Move move) + explicit BestMoveCommand(Chess::Move move, Optional<Chess::Move> move_to_ponder = {}) : Command(Command::Type::BestMove) , m_move(::move(move)) + , m_move_to_ponder(::move(move_to_ponder)) { } @@ -240,9 +241,11 @@ public: virtual ErrorOr<String> to_string() const override; Chess::Move move() const { return m_move; } + Optional<Chess::Move> move_to_ponder() const { return m_move_to_ponder; } private: Chess::Move m_move; + Optional<Chess::Move> m_move_to_ponder; }; class InfoCommand : public Command { |