2020-08-21 02:04:08 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
2023-04-30 19:05:11 +03:00
|
|
|
* Copyright (c) 2023, Tim Ledbetter <timledbetter@gmail.com>
|
2020-08-21 02:04:08 +03:00
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-08-21 02:04:08 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2022-08-14 17:39:32 +03:00
|
|
|
#include "MCTSTree.h"
|
2020-08-21 02:04:08 +03:00
|
|
|
#include <LibChess/Chess.h>
|
|
|
|
#include <LibChess/UCIEndpoint.h>
|
|
|
|
|
|
|
|
class ChessEngine : public Chess::UCI::Endpoint {
|
2023-05-07 02:59:10 +03:00
|
|
|
C_OBJECT_ABSTRACT(ChessEngine)
|
2020-08-21 02:04:08 +03:00
|
|
|
public:
|
2023-05-07 02:59:10 +03:00
|
|
|
static ErrorOr<NonnullRefPtr<ChessEngine>> try_create(NonnullOwnPtr<Core::File> in, NonnullOwnPtr<Core::File> out)
|
|
|
|
{
|
|
|
|
auto engine = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) ChessEngine()));
|
|
|
|
TRY(engine->set_in(move(in)));
|
|
|
|
engine->set_out(move(out));
|
|
|
|
return engine;
|
|
|
|
}
|
2022-03-24 05:58:03 +03:00
|
|
|
virtual ~ChessEngine() override = default;
|
2020-08-21 02:04:08 +03:00
|
|
|
|
2021-11-01 01:38:04 +03:00
|
|
|
virtual void handle_uci() override;
|
2022-04-01 20:58:27 +03:00
|
|
|
virtual void handle_position(Chess::UCI::PositionCommand const&) override;
|
|
|
|
virtual void handle_go(Chess::UCI::GoCommand const&) override;
|
2023-04-02 01:18:10 +03:00
|
|
|
virtual void handle_quit() override;
|
2023-04-26 21:02:42 +03:00
|
|
|
virtual void handle_ucinewgame() override;
|
2023-04-02 23:04:27 +03:00
|
|
|
virtual void handle_unexpected_eof() override;
|
2023-04-02 01:18:10 +03:00
|
|
|
|
|
|
|
Function<void(int)> on_quit;
|
2021-11-01 01:38:04 +03:00
|
|
|
|
|
|
|
private:
|
2023-05-07 02:59:10 +03:00
|
|
|
ChessEngine()
|
|
|
|
: Endpoint()
|
2020-08-21 02:04:08 +03:00
|
|
|
{
|
2023-04-30 19:05:11 +03:00
|
|
|
on_command_read_error = [](auto command, auto error) {
|
|
|
|
outln("{}: '{}'", error, command);
|
|
|
|
};
|
2020-08-21 02:04:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Chess::Board m_board;
|
2022-08-14 17:39:32 +03:00
|
|
|
Optional<MCTSTree> m_last_tree;
|
2020-08-21 02:04:08 +03:00
|
|
|
};
|