summaryrefslogtreecommitdiff
path: root/Userland/Services/ChessEngine/ChessEngine.h
blob: 5422878843e1b31af76bd006b7cbfc596c37e5a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
 * 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;
};