BenBot 1.7.5
A chess engine
Loading...
Searching...
No Matches
EngineBase.hpp
Go to the documentation of this file.
1/*
2 * ======================================================================================
3 *
4 * ░▒▓███████▓▒░░▒▓████████▓▒░▒▓███████▓▒░ ░▒▓███████▓▒░ ░▒▓██████▓▒░▒▓████████▓▒░
5 * ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
6 * ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
7 * ░▒▓███████▓▒░░▒▓██████▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓███████▓▒░░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
8 * ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
9 * ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
10 * ░▒▓███████▓▒░░▒▓████████▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓███████▓▒░ ░▒▓██████▓▒░ ░▒▓█▓▒░
11 *
12 * ======================================================================================
13 */
14
19
20#pragma once
21
23#include <span>
24#include <string>
25#include <string_view>
26
27namespace chess::game {
28struct Position;
29} // namespace chess::game
30
31namespace chess::uci {
32
33using game::Position;
34using std::string_view;
35
36struct Option;
37
51struct EngineBase {
52 EngineBase() = default;
53
54 virtual ~EngineBase();
55
56 EngineBase(const EngineBase&) = default;
57 EngineBase(EngineBase&&) = default;
58 EngineBase& operator=(const EngineBase&) = default;
60
65 [[nodiscard]] virtual auto get_name() const -> std::string = 0;
66
68 [[nodiscard]] virtual auto get_author() const -> string_view = 0;
69
71 [[nodiscard]] virtual auto get_options() -> std::span<Option*> { return { }; }
72
77 virtual void wait() { }
78
82 [[nodiscard]] virtual auto is_searching() const noexcept -> bool = 0;
83
92 virtual void new_game([[maybe_unused]] bool firstCall) { }
93
95 virtual void abort_search() { }
96
101 virtual void ponder_hit() { }
102
104 virtual void set_position([[maybe_unused]] const Position& pos) { }
105
110 virtual void go([[maybe_unused]] const GoCommandOptions& opts) = 0;
111
113 virtual void set_debug([[maybe_unused]] bool shouldDebug) { }
114
121 void handle_command(string_view command);
122
128 [[maybe_unused]] string_view command,
129 [[maybe_unused]] string_view options) { }
130
137 void loop();
138
142 virtual void handle_registration([[maybe_unused]] const RegisterOptions& opts) { }
143
144private:
145 void respond_to_uci();
146
147 void handle_setpos(string_view arguments);
148 void handle_setoption(string_view arguments);
149
150 bool shouldExit { false }; // used as flag for exiting the loop() function
151
152 bool initialized { false };
153
154 Position position;
155};
156
157} // namespace chess::uci
optional< RegisterNowOptions > RegisterOptions
virtual auto get_author() const -> string_view=0
virtual void handle_registration(const RegisterOptions &opts)
virtual void ponder_hit()
virtual void handle_custom_command(string_view command, string_view options)
virtual auto get_name() const -> std::string=0
virtual auto get_options() -> std::span< Option * >
virtual void set_position(const Position &pos)
void handle_command(string_view command)
virtual void go(const GoCommandOptions &opts)=0
virtual auto is_searching() const noexcept -> bool=0
virtual void wait()
virtual void new_game(bool firstCall)
EngineBase & operator=(EngineBase &&)=default
EngineBase & operator=(const EngineBase &)=default
virtual void abort_search()
virtual void set_debug(bool shouldDebug)
EngineBase(const EngineBase &)=default
EngineBase(EngineBase &&)=default