2020-08-19 17:53:50 -06:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-08-19 17:53:50 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/Function.h>
|
|
|
|
#include <LibChess/UCIEndpoint.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
class Engine : public Chess::UCI::Endpoint {
|
|
|
|
C_OBJECT(Engine)
|
|
|
|
public:
|
|
|
|
virtual ~Engine() override;
|
|
|
|
|
2021-11-11 00:55:02 +01:00
|
|
|
Engine(StringView command);
|
2020-08-19 17:53:50 -06:00
|
|
|
|
2022-04-01 20:58:27 +03:00
|
|
|
Engine(Engine const&) = delete;
|
|
|
|
Engine& operator=(Engine const&) = delete;
|
2020-08-19 17:53:50 -06:00
|
|
|
|
2022-04-01 20:58:27 +03:00
|
|
|
virtual void handle_bestmove(Chess::UCI::BestMoveCommand const&) override;
|
2020-08-19 17:53:50 -06:00
|
|
|
|
|
|
|
template<typename Callback>
|
2022-04-01 20:58:27 +03:00
|
|
|
void get_best_move(Chess::Board const& board, int time_limit, Callback&& callback)
|
2020-08-19 17:53:50 -06:00
|
|
|
{
|
|
|
|
send_command(Chess::UCI::PositionCommand({}, board.moves()));
|
|
|
|
Chess::UCI::GoCommand go_command;
|
|
|
|
go_command.movetime = time_limit;
|
|
|
|
send_command(go_command);
|
|
|
|
m_bestmove_callback = move(callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Function<void(Chess::Move)> m_bestmove_callback;
|
|
|
|
pid_t m_pid { -1 };
|
|
|
|
};
|