mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:38:11 +00:00

ChessEngine and the chess GUI will no longer crash on error while reading UCI commands. ChessEngine will print a message to the standard output, while the GUI will ignore unknown commands. Both will print the error to the debug log if the UCI_DEBUG flag is enabled. Trailing and preceding whitespace is now stripped from commands before they are parsed. Commands which are just whitespace no longer produce errors.
39 lines
1.1 KiB
C++
39 lines
1.1 KiB
C++
/*
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
|
* Copyright (c) 2023, Tim Ledbetter <timledbetter@gmail.com>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "MCTSTree.h"
|
|
#include <LibChess/Chess.h>
|
|
#include <LibChess/UCIEndpoint.h>
|
|
|
|
class ChessEngine : public Chess::UCI::Endpoint {
|
|
C_OBJECT(ChessEngine)
|
|
public:
|
|
virtual ~ChessEngine() override = default;
|
|
|
|
virtual void handle_uci() override;
|
|
virtual void handle_position(Chess::UCI::PositionCommand const&) override;
|
|
virtual void handle_go(Chess::UCI::GoCommand const&) override;
|
|
virtual void handle_quit() override;
|
|
virtual void handle_ucinewgame() override;
|
|
virtual void handle_unexpected_eof() override;
|
|
|
|
Function<void(int)> on_quit;
|
|
|
|
private:
|
|
ChessEngine(NonnullRefPtr<Core::IODevice> in, NonnullRefPtr<Core::IODevice> out)
|
|
: Endpoint(in, out)
|
|
{
|
|
on_command_read_error = [](auto command, auto error) {
|
|
outln("{}: '{}'", error, command);
|
|
};
|
|
}
|
|
|
|
Chess::Board m_board;
|
|
Optional<MCTSTree> m_last_tree;
|
|
};
|