40using std::string_view;
47 using Callback = std::function<void(string_view)>;
72 return [callback = std::move(func)]([[maybe_unused]]
const string_view args) {
105 [[nodiscard]]
virtual auto get_name() const -> std::
string = 0;
108 [[nodiscard]] virtual auto
get_author() const -> string_view = 0;
129 virtual
void new_game([[maybe_unused]]
bool firstCall) { }
176 return standardUCICommands;
197 return standardUCIOptions;
203 return debugMode.load(std::memory_order_relaxed);
209 debugMode.store(shouldDebug, std::memory_order_relaxed);
221 sanitizeIncomingPositions.store(shouldSanitize, std::memory_order_release);
228 virtual void set_ponder([[maybe_unused]]
const bool shouldPonder) { }
237 "Sets the transposition table size (in MB)",
238 [
this](
const int sizeMB) {
253 "Controls whether pondering is allowed.",
254 [
this](
const bool shouldPonder) {
set_ponder(shouldPonder); }
260 void respond_to_uci();
261 void respond_to_isready();
262 void respond_to_newgame();
264 void handle_setpos(string_view arguments);
265 void handle_setoption(string_view arguments);
268 std::atomic_bool::is_always_lock_free,
269 "Platform doesn't support lock-free atomic operations");
271 std::atomic_bool shouldExit {
false };
272 std::atomic_bool initialized {
false };
273 std::atomic_bool debugMode {
false };
274 std::atomic_bool sanitizeIncomingPositions {
false };
278 std::array<EngineCommand, 11uz> standardUCICommands {
282 .description =
"Initialize UCI communication",
287 .description =
"Wait for engine to complete background tasks",
290 .name =
"ucinewgame",
292 .description =
"Initialize a new game",
297 .description =
"Exit the engine as quickly as possible",
302 .description =
"Abort the current search, if any",
307 .description =
"Indicate that the user played the ponder move",
311 .action = [
this](
const string_view args) { handle_setpos(args); },
312 .description =
"Set the position on the engine's internal board",
313 .argsHelp =
"[startpos|fen <fen>] [moves <move...>]" },
317 .description =
"Start a search",
321 .action = [
this](
const string_view args) { handle_setoption(args); },
322 .description =
"Set UCI option values",
323 .argsHelp =
"[name <name>] [value <value>]" },
326 .action = [
this](
const string_view args)
noexcept {
set_debug_mode(args ==
"on"); },
327 .description =
"Enable/disable engine debug mode",
328 .argsHelp =
"[on|off]" },
331 .action = [
this](
const string_view args) {
334 .description =
"Handle license registration",
338 std::array<Option*, 2uz> standardUCIOptions {
optional< RegisterNowOptions > RegisterOptions
auto parse_go_options(string_view options, const Position ¤tPosition) -> GoCommandOptions
auto parse_register_options(string_view options) -> RegisterOptions
virtual void set_ponder(const bool shouldPonder)
virtual auto get_author() const -> string_view=0
virtual void handle_registration(const RegisterOptions &opts)
virtual void ponder_hit()
std::span< const EngineCommand > CommandList
virtual auto get_name() const -> std::string=0
std::span< Option * > OptionList
EngineBase(EngineBase &&)=delete
virtual void resize_transposition_table(const size_t sizeMB)
virtual void set_position(const Position &pos)
void handle_command(string_view command)
virtual void go(const GoCommandOptions &opts)=0
void set_sanitize_positions(const bool shouldSanitize) noexcept
virtual auto is_searching() const noexcept -> bool=0
virtual auto get_custom_uci_commands() const noexcept -> CommandList
EngineBase & operator=(EngineBase &&)=delete
virtual void new_game(bool firstCall)
auto get_standard_uci_commands() const noexcept -> CommandList
virtual void abort_search()
EngineBase & operator=(const EngineBase &)=delete
auto is_debug_mode() const noexcept -> bool
EngineBase(const EngineBase &)=delete
void set_debug_mode(const bool shouldDebug) noexcept
auto get_standard_uci_options() noexcept -> OptionList
virtual auto get_custom_uci_options() noexcept -> OptionList
std::function< void(string_view)> Callback
static auto void_cb(std::function< void()> &&func) -> Callback