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:

Public Member Functions

 EngineBase ()=default
 EngineBase (const EngineBase &)=default
 EngineBase (EngineBase &&)=default
virtual ~EngineBase ()
virtual void abort_search ()
virtual auto get_author () const -> string_view=0
virtual auto get_name () const -> std::string=0
virtual auto get_options () -> std::span< Option * >
virtual void go (const GoCommandOptions &opts)=0
void handle_command (string_view command)
virtual void handle_custom_command (string_view command, string_view options)
virtual void handle_registration (const RegisterOptions &opts)
virtual auto is_searching () const noexcept -> bool=0
void loop ()
virtual void new_game (bool firstCall)
EngineBaseoperator= (const EngineBase &)=default
EngineBaseoperator= (EngineBase &&)=default
virtual void ponder_hit ()
virtual void set_debug (bool shouldDebug)
virtual void set_position (const Position &pos)
virtual void wait ()

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 51 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 & )
default

◆ EngineBase() [3/3]

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

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 95 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_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_options()

virtual auto chess::uci::EngineBase::get_options ( ) -> std::span< Option * >
inlinenodiscardvirtual

This must return the list of all options the engine supports.

Reimplemented in ben_bot::Engine.

Definition at line 71 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_custom_command()

virtual void chess::uci::EngineBase::handle_custom_command ( string_view command,
string_view options )
inlinevirtual

Any command input string not recognized as a standard UCI command will invoke this function. Engines can implement custom commands by overriding this function. The "command" argument will be the first word of the input command line.

Reimplemented in ben_bot::Engine.

Definition at line 127 of file EngineBase.hpp.

◆ 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 142 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 92 of file EngineBase.hpp.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

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

◆ set_debug()

virtual void chess::uci::EngineBase::set_debug ( bool shouldDebug)
inlinevirtual

Called when the "debug" command is received.

Reimplemented in ben_bot::Engine.

Definition at line 113 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 104 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 77 of file EngineBase.hpp.


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