BenBot 1.7.5
A chess engine
Loading...
Searching...
No Matches
chess::uci::EngineBase Struct Referenceabstract

#include <libchess/uci/EngineBase.hpp>

Inheritance diagram for chess::uci::EngineBase:
Collaboration diagram for chess::uci::EngineBase:

Public Types

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

Public Member Functions

 EngineBase ()=default
 EngineBase (const EngineBase &)=delete
 EngineBase (EngineBase &&)=delete
virtual ~EngineBase ()
virtual void abort_search ()
virtual auto get_author () const -> string_view=0
virtual auto get_custom_uci_commands () const noexcept -> CommandList
virtual auto get_custom_uci_options () noexcept -> OptionList
virtual auto get_name () const -> std::string=0
auto get_standard_uci_commands () const noexcept -> CommandList
auto get_standard_uci_options () noexcept -> OptionList
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
virtual auto is_searching () const noexcept -> bool=0
void loop ()
virtual void new_game (bool firstCall)
EngineBaseoperator= (const EngineBase &)=delete
EngineBaseoperator= (EngineBase &&)=delete
virtual void ponder_hit ()
virtual void resize_transposition_table (const size_t sizeMB)
void set_debug_mode (const bool shouldDebug) noexcept
virtual void set_ponder (const bool shouldPonder)
virtual void set_position (const Position &pos)
void set_sanitize_positions (const bool shouldSanitize) noexcept
virtual void wait ()

Public Attributes

IntOption opt_Hash
BoolOption opt_Ponder

Detailed Description

A base class for UCI [3] chess engines.

This class provides handling of UCI command parsing, so that the engine implementation can focus purely on implementing evaluation and search. UCI printing is provided by the functions in the uci::printing namespace.

To use this class, implement a derived class, then in your program's main() function, create an instance of your derived engine class and call its loop() method.

Definition at line 91 of file EngineBase.hpp.

Member Typedef Documentation

◆ CommandList

Typedef for a view of a list of engine commands.

Definition at line 171 of file EngineBase.hpp.

◆ OptionList

Typedef for a view of a list of engine options.

Definition at line 186 of file EngineBase.hpp.

Constructor & Destructor Documentation

◆ EngineBase() [1/3]

chess::uci::EngineBase::EngineBase ( )
default

◆ ~EngineBase()

virtual chess::uci::EngineBase::~EngineBase ( )
virtual

◆ EngineBase() [2/3]

chess::uci::EngineBase::EngineBase ( const EngineBase & )
delete

◆ EngineBase() [3/3]

chess::uci::EngineBase::EngineBase ( EngineBase && )
delete

Member Function Documentation

◆ abort_search()

virtual void chess::uci::EngineBase::abort_search ( )
inlinevirtual

This function is called when the search should be exited.

Reimplemented in ben_bot::Engine.

Definition at line 132 of file EngineBase.hpp.

◆ get_author()

virtual auto chess::uci::EngineBase::get_author ( ) const -> string_view
nodiscardpure virtual

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

Implemented in ben_bot::Engine.

◆ get_custom_uci_commands()

virtual auto chess::uci::EngineBase::get_custom_uci_commands ( ) const -> CommandList
inlinenodiscardvirtualnoexcept

Subclasses should overload this to return their custom UCI commands.

Reimplemented in ben_bot::Engine.

Definition at line 180 of file EngineBase.hpp.

◆ get_custom_uci_options()

virtual auto chess::uci::EngineBase::get_custom_uci_options ( ) -> OptionList
inlinenodiscardvirtualnoexcept

Subclasses should overload this to return their custom UCI options.

Reimplemented in ben_bot::Engine.

Definition at line 189 of file EngineBase.hpp.

◆ get_name()

virtual auto chess::uci::EngineBase::get_name ( ) const -> std::string
nodiscardpure virtual

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.

Implemented in ben_bot::Engine.

◆ get_standard_uci_commands()

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

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

Definition at line 174 of file EngineBase.hpp.

◆ get_standard_uci_options()

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

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

Definition at line 195 of file EngineBase.hpp.

◆ go()

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

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)

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)
inlinevirtual

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

Definition at line 168 of file EngineBase.hpp.

◆ is_debug_mode()

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

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

Definition at line 201 of file EngineBase.hpp.

◆ is_searching()

virtual auto chess::uci::EngineBase::is_searching ( ) const -> bool
nodiscardpure virtualnoexcept

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

Implemented in ben_bot::Engine.

◆ loop()

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

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()

virtual void chess::uci::EngineBase::new_game ( bool firstCall)
inlinevirtual

This function will be called when the "ucinewgame" command is received. 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 in ben_bot::Engine.

Definition at line 129 of file EngineBase.hpp.

◆ operator=() [1/2]

EngineBase & chess::uci::EngineBase::operator= ( const EngineBase & )
delete

◆ operator=() [2/2]

EngineBase & chess::uci::EngineBase::operator= ( EngineBase && )
delete

◆ ponder_hit()

virtual void chess::uci::EngineBase::ponder_hit ( )
inlinevirtual

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 in ben_bot::Engine.

Definition at line 138 of file EngineBase.hpp.

◆ resize_transposition_table()

virtual void chess::uci::EngineBase::resize_transposition_table ( const size_t sizeMB)
inlinevirtual

Subclasses should implement this to resize their transposition table.

Reimplemented in ben_bot::Engine.

Definition at line 225 of file EngineBase.hpp.

◆ set_debug_mode()

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

Sets the engine's debugging mode.

Definition at line 207 of file EngineBase.hpp.

◆ set_ponder()

virtual void chess::uci::EngineBase::set_ponder ( const bool shouldPonder)
inlinevirtual

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

Reimplemented in ben_bot::Engine.

Definition at line 228 of file EngineBase.hpp.

◆ set_position()

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

Called when a new position is received from the GUI.

Reimplemented in ben_bot::Engine.

Definition at line 141 of file EngineBase.hpp.

◆ set_sanitize_positions()

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

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 219 of file EngineBase.hpp.

◆ wait()

virtual void chess::uci::EngineBase::wait ( )
inlinevirtual

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 in ben_bot::Engine.

Definition at line 114 of file EngineBase.hpp.

Member Data Documentation

◆ opt_Hash

IntOption chess::uci::EngineBase::opt_Hash
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));
}
}
virtual void resize_transposition_table(const size_t sizeMB)

Standard UCI option for hash size.

Definition at line 234 of file EngineBase.hpp.

◆ opt_Ponder

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

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 250 of file EngineBase.hpp.


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