37using std::string_view;
44 using Callback = std::function<void(string_view)>;
69 return [callback = std::move(func)]([[maybe_unused]]
const string_view args) {
102 [[nodiscard]]
virtual auto get_name() const -> std::
string = 0;
105 [[nodiscard]] virtual auto
get_author() const -> string_view = 0;
128 virtual
void new_game([[maybe_unused]]
bool firstCall) { }
209 return debugMode.load(std::memory_order_relaxed);
215 debugMode.store(shouldDebug, std::memory_order_relaxed);
227 sanitizeIncomingPositions.store(shouldSanitize, std::memory_order_release);
234 virtual void set_ponder([[maybe_unused]]
const bool shouldPonder) { }
243 "Sets the transposition table size (in MB).",
244 [
this](
const int sizeMB) {
259 "Controls whether pondering is allowed.",
260 [
this](
const bool shouldPonder) {
set_ponder(shouldPonder); }
273 .description =
"Initialize UCI communication",
278 .description =
"Wait for engine to complete background tasks",
281 .name =
"ucinewgame",
283 .description =
"Initialize a new game",
288 .description =
"Exit the engine as quickly as possible",
293 .description =
"Abort the current search, if any",
298 .description =
"Indicate that the user played the ponder move",
302 .action = [
this](
const string_view args) { handle_setpos(args); },
303 .description =
"Set the position on the engine's internal board",
304 .argsHelp =
"[startpos|fen <fen>] [moves <move...>]" },
307 .action = [
this](
const string_view args) { handle_go(args); },
308 .description =
"Start a search",
312 .action = [
this](
const string_view args) { handle_setoption(args); },
313 .description =
"Set UCI option values",
314 .argsHelp =
"[name <name>] [value <value>]" },
317 .action = [
this](
const string_view args)
noexcept {
set_debug_mode(args ==
"on"); },
318 .description =
"Enable/disable engine debug mode",
319 .argsHelp =
"[on|off]" },
322 .action = [
this](
const string_view args) {
325 .description =
"Handle license registration",
334 void respond_to_uci();
335 void respond_to_isready();
336 void respond_to_newgame();
338 void handle_setpos(string_view arguments);
339 void handle_setoption(string_view arguments);
340 void handle_go(string_view arguments);
343 std::atomic_bool::is_always_lock_free,
344 "Platform doesn't support lock-free atomic operations");
348 std::atomic_bool shouldExit {
false };
349 std::atomic_bool initialized {
false };
350 std::atomic_bool debugMode {
false };
351 std::atomic_bool sanitizeIncomingPositions {
false };
optional< RegisterNowOptions > RegisterOptions
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)
void handle_command(string_view command)
virtual void go(const GoCommandOptions &opts)=0
void set_sanitize_positions(const bool shouldSanitize) noexcept
std::array< Option *, 2uz > standardUCIOptions
virtual auto is_searching() const noexcept -> bool=0
virtual void position_changed(const Position &pos)
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
void set_position(const Position &pos)
auto get_position() const -> const Position &
virtual void abort_search()
EngineBase & operator=(const EngineBase &)=delete
auto is_debug_mode() const noexcept -> bool
std::array< EngineCommand, 11uz > standardUCICommands
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