BenBot 1.7.5
A chess engine
Loading...
Searching...
No Matches
ben_bot::Engine Class Referenceabstract

#include <libbenbot/engine/Engine.hpp>

Inheritance diagram for ben_bot::Engine:
Collaboration diagram for ben_bot::Engine:

Public Types

using CommandList = std::span<const EngineCommand>
using OptionList = std::span<Option*>

Public Member Functions

 Engine ()=default
 Engine (const Engine &)=delete
 Engine (Engine &&)=delete
 ~Engine () override=default
auto get_position () const -> const Position &
auto get_pretty_print_move_format () const -> MoveFormat
auto get_search_options () const noexcept -> const search::Options &
auto get_standard_uci_commands () const noexcept -> CommandList
auto get_standard_uci_options () noexcept -> OptionList
void go (const search::Options &opts)
virtual void go (const GoCommandOptions &opts)=0
void handle_command (string_view command)
virtual void handle_registration (const RegisterOptions &opts)
auto is_debug_mode () const noexcept -> bool
void loop ()
Engine & operator= (const Engine &)=delete
Engine & operator= (Engine &&)=delete
auto pretty_print_move (Move move, const Position &position) const -> std::string
void read_config_file (const std::filesystem::path &file)
auto restore_state_from_string (string_view state) -> std::expected< void, std::string >
void set_debug_mode (const bool shouldDebug) noexcept
void set_position (const Position &pos)
void set_sanitize_positions (const bool shouldSanitize) noexcept
void set_search_options (const search::Options &opts)
auto state_to_string () const -> std::string

Public Attributes

IntOption opt_Hash
BoolOption opt_Ponder

Protected Member Functions

virtual auto create_search_callbacks () -> search::Callbacks

Protected Attributes

std::array< EngineCommand, 11uz > standardUCICommands
std::array< Option *, 2uz > standardUCIOptions

Private Member Functions

void abort_search () override
auto get_author () const -> string_view override
auto get_custom_uci_commands () const noexcept -> CommandList override
auto get_custom_uci_options () noexcept -> OptionList override
auto get_name () const -> std::string override
void go (const uci::GoCommandOptions &opts) override
auto is_searching () const noexcept -> bool override
void new_game (bool firstCall) override
void ponder_hit () override
void position_changed (const Position &pos) override
void resize_transposition_table (const size_t sizeMB) override
void set_ponder (const bool shouldPonder) override
void wait () override

Detailed Description

The BenBot UCI engine class.

Definition at line 57 of file Engine.hpp.

Member Typedef Documentation

◆ CommandList

using chess::uci::EngineBase::CommandList = std::span<const EngineCommand>
inherited

Typedef for a view of a list of engine commands.

Definition at line 177 of file EngineBase.hpp.

◆ OptionList

using chess::uci::EngineBase::OptionList = std::span<Option*>
inherited

Typedef for a view of a list of engine options.

Definition at line 192 of file EngineBase.hpp.

Constructor & Destructor Documentation

◆ Engine() [1/3]

ben_bot::Engine::Engine ( )
default

◆ ~Engine()

ben_bot::Engine::~Engine ( )
overridedefault

◆ Engine() [2/3]

ben_bot::Engine::Engine ( const Engine & )
delete

◆ Engine() [3/3]

ben_bot::Engine::Engine ( Engine && )
delete

Member Function Documentation

◆ abort_search()

void ben_bot::Engine::abort_search ( )
inlineoverrideprivatevirtual

This function is called when the search should be exited.

Reimplemented from chess::uci::EngineBase.

Definition at line 124 of file Engine.hpp.

◆ create_search_callbacks()

virtual auto ben_bot::Engine::create_search_callbacks ( ) -> search::Callbacks
nodiscardprotectedvirtual

This function is used to initialize the search context's result callbacks. The default implementation returns either a console pretty printer or a UCI printer depending on the value of the pretty printing parameter, but other engine use cases can override this to return other sets of callbacks.

◆ get_author()

auto ben_bot::Engine::get_author ( ) const -> string_view
inlinenodiscardoverrideprivatevirtual

This must return the name of the engine's author.

Implements chess::uci::EngineBase.

Definition at line 114 of file Engine.hpp.

◆ get_custom_uci_commands()

auto ben_bot::Engine::get_custom_uci_commands ( ) const -> CommandList
inlinenodiscardoverrideprivatevirtualnoexcept

Subclasses should overload this to return their custom UCI commands.

Reimplemented from chess::uci::EngineBase.

Definition at line 137 of file Engine.hpp.

◆ get_custom_uci_options()

auto ben_bot::Engine::get_custom_uci_options ( ) -> OptionList
inlinenodiscardoverrideprivatevirtualnoexcept

Subclasses should overload this to return their custom UCI options.

Reimplemented from chess::uci::EngineBase.

Definition at line 132 of file Engine.hpp.

◆ get_name()

auto ben_bot::Engine::get_name ( ) const -> std::string
nodiscardoverrideprivatevirtual

This must return the name of the engine. The returned string may optionally contain the engine's current version, such as BenBot 1.2.0.

Implements chess::uci::EngineBase.

◆ get_position()

auto chess::uci::EngineBase::get_position ( ) const -> const Position &
inlinenodiscardinherited

Returns the engine's current position.

Definition at line 147 of file EngineBase.hpp.

◆ get_pretty_print_move_format()

auto ben_bot::Engine::get_pretty_print_move_format ( ) const -> MoveFormat
inlinenodiscard

Returns the move format being used to pretty-print moves.

Definition at line 95 of file Engine.hpp.

◆ get_search_options()

auto ben_bot::Engine::get_search_options ( ) const -> const search::Options &
inlinenodiscardnoexcept

Returns the engine's current search parameters, set by the last go command.

Definition at line 86 of file Engine.hpp.

◆ get_standard_uci_commands()

auto chess::uci::EngineBase::get_standard_uci_commands ( ) const -> CommandList
inlinenodiscardnoexceptinherited

Returns the engine's list of supported standard UCI commands.

Definition at line 180 of file EngineBase.hpp.

◆ get_standard_uci_options()

auto chess::uci::EngineBase::get_standard_uci_options ( ) -> OptionList
inlinenodiscardnoexceptinherited

Returns the engine's list of supported standard UCI commands.

Definition at line 201 of file EngineBase.hpp.

◆ go() [1/3]

void ben_bot::Engine::go ( const search::Options & opts)

Starts a search with the specified options.

◆ go() [2/3]

void ben_bot::Engine::go ( const uci::GoCommandOptions & opts)
overrideprivate

◆ go() [3/3]

virtual void chess::uci::EngineBase::go ( const GoCommandOptions & opts)
pure virtualinherited

Called when the "go" command is received. The engine should begin searching. After this function has been called, the engine should print to stdout a line of the form "bestmove <from><to>".

◆ handle_command()

void chess::uci::EngineBase::handle_command ( string_view command)
inherited

Handles a UCI command. Typically you will not call this directly, you'll just invoke loop(), but this method can be used to manually invoke UCI commands if needed.

See also
loop()

◆ handle_registration()

virtual void chess::uci::EngineBase::handle_registration ( const RegisterOptions & opts)
inlinevirtualinherited

Called when the user send a "register" command. The engine may simply do nothing if it does not require registration.

Definition at line 174 of file EngineBase.hpp.

◆ is_debug_mode()

auto chess::uci::EngineBase::is_debug_mode ( ) const -> bool
inlinenodiscardnoexceptinherited

Returns true if the engine's debugging mode is active.

Definition at line 207 of file EngineBase.hpp.

◆ is_searching()

auto ben_bot::Engine::is_searching ( ) const -> bool
inlineoverrideprivatevirtualnoexcept

This function must return true if a search is currently in progress. This function should be thread-safe.

Implements chess::uci::EngineBase.

Definition at line 130 of file Engine.hpp.

◆ loop()

void chess::uci::EngineBase::loop ( )
inherited

Runs the engine's event loop. This function blocks while reading from stdin. The calling thread becomes the engine's "main thread".

See also
handle_command()

◆ new_game()

void ben_bot::Engine::new_game ( bool firstCall)
overrideprivatevirtual

This function will be called when the "ucinewgame" command is received. Since GUIs aren't required to send "ucinewgame", it's also called before handling the first command if that command isn't "ucinewgame". This should flush any game-specific data structures such as hash tables, transposition table, etc. wait() will be called after this, before the next search begins.

Parameters
firstCallTrue if this is the first time new_game() has been called.

Reimplemented from chess::uci::EngineBase.

◆ operator=() [1/2]

Engine & ben_bot::Engine::operator= ( const Engine & )
delete

◆ operator=() [2/2]

Engine & ben_bot::Engine::operator= ( Engine && )
delete

◆ ponder_hit()

void ben_bot::Engine::ponder_hit ( )
inlineoverrideprivatevirtual

This function is called when the "ponderhit" command is received. This means that the engine was told to ponder on the same move the user has played. The engine should continue searching but switch from pondering to normal search.

Reimplemented from chess::uci::EngineBase.

Definition at line 126 of file Engine.hpp.

◆ position_changed()

void ben_bot::Engine::position_changed ( const Position & pos)
inlineoverrideprivatevirtual

Subclasses can implement this to be informed when the position has changed.

Reimplemented from chess::uci::EngineBase.

Definition at line 118 of file Engine.hpp.

◆ pretty_print_move()

auto ben_bot::Engine::pretty_print_move ( Move move,
const Position & position ) const -> std::string
nodiscard

Pretty-prints a move using the engine's current settings.

◆ read_config_file()

void ben_bot::Engine::read_config_file ( const std::filesystem::path & file)

Loads the engine's state from a configuration file at the given path.

◆ resize_transposition_table()

void ben_bot::Engine::resize_transposition_table ( const size_t sizeMB)
inlineoverrideprivatevirtual

Subclasses should implement this to resize their transposition table.

Reimplemented from chess::uci::EngineBase.

Definition at line 163 of file Engine.hpp.

◆ restore_state_from_string()

auto ben_bot::Engine::restore_state_from_string ( string_view state) -> std::expected< void, std::string >

Restores the engine's state from a stringified version. Options that are missing from the saved state retain their current values, and options with invalid saved values are skipped. Returns an error if the state string could not be parsed at all.

◆ set_debug_mode()

void chess::uci::EngineBase::set_debug_mode ( const bool shouldDebug)
inlinenoexceptinherited

Sets the engine's debugging mode.

Definition at line 213 of file EngineBase.hpp.

◆ set_ponder()

void ben_bot::Engine::set_ponder ( const bool shouldPonder)
inlineoverrideprivatevirtual

Subclasses can implement this to be informed when the ponder parameter changes.

Reimplemented from chess::uci::EngineBase.

Definition at line 168 of file Engine.hpp.

◆ set_position()

void chess::uci::EngineBase::set_position ( const Position & pos)
inlineinherited

Sets the engine's current position.

Definition at line 140 of file EngineBase.hpp.

◆ set_sanitize_positions()

void chess::uci::EngineBase::set_sanitize_positions ( const bool shouldSanitize)
inlinenoexceptinherited

Tells the base class whether to sanitize incoming positions when processing the position command. When sanitizing is on, after evaluating each position command, the engine performs some basic checks to determine if the position is illegal, and if so, prints a diagnostic message and reverts the internal board to the previous position.

Definition at line 225 of file EngineBase.hpp.

◆ set_search_options()

void ben_bot::Engine::set_search_options ( const search::Options & opts)
inline

Sets the options to be used for the next search.

Definition at line 83 of file Engine.hpp.

◆ state_to_string()

auto ben_bot::Engine::state_to_string ( ) const -> std::string
nodiscard

Saves the engine's state to a string.

◆ wait()

void ben_bot::Engine::wait ( )
inlineoverrideprivatevirtual

This function will be called when the "isready" command is received, and may block while waiting for background tasks to complete. This function should be thread-safe.

Reimplemented from chess::uci::EngineBase.

Definition at line 128 of file Engine.hpp.

Member Data Documentation

◆ opt_Hash

IntOption chess::uci::EngineBase::opt_Hash
inherited
Initial value:
{
"Hash",
1, 2048, 16,
"Sets the transposition table size (in MB).",
[this](const int sizeMB) {
assert(sizeMB >= 0);
resize_transposition_table(static_cast<size_t>(sizeMB));
}
}
void resize_transposition_table(const size_t sizeMB) override
Definition Engine.hpp:163

Standard UCI option for hash size.

Definition at line 240 of file EngineBase.hpp.

◆ opt_Ponder

BoolOption chess::uci::EngineBase::opt_Ponder
inherited
Initial value:
{
"Ponder",
false,
"Controls whether pondering is allowed.",
[this](const bool shouldPonder) { set_ponder(shouldPonder); }
}
void set_ponder(const bool shouldPonder) override
Definition Engine.hpp:168

Standard UCI option for pondering. The engine doesn't start pondering on its own without explicitly being told to via another go command; this option is needed to inform the GUI that the engine supports pondering, and also gives the engine the opportunity to adjust its time management algorithm when pondering is enabled.

Definition at line 256 of file EngineBase.hpp.

◆ standardUCICommands

std::array<EngineCommand, 11uz> chess::uci::EngineBase::standardUCICommands
protectedinherited

Definition at line 269 of file EngineBase.hpp.

◆ standardUCIOptions

std::array<Option*, 2uz> chess::uci::EngineBase::standardUCIOptions
protectedinherited
Initial value:

Definition at line 329 of file EngineBase.hpp.


The documentation for this class was generated from the following file: