io-chess
UCI chess engine
Loading...
Searching...
No Matches
UciProtocol Class Reference

Main engine controller implementing the UCI protocol. More...

#include <UCI.h>

Collaboration diagram for UciProtocol:

Public Member Functions

 UciProtocol (const std::string &modelPath, bool useSimpleEval=false, const std::string &tbPath="", const std::string &bookPath="", const std::string &bookPath2="", int evalThreads=0)
 Constructs the UCI Protocol handler.
 ~UciProtocol ()
void loop ()
 The main blocking loop that reads commands from standard input.
void resizeHash (size_t mb)
void updateThreads (int numThreads)
void reinitEngine ()
void updateEvalContexts ()
void initTablebase ()
void loadBooks ()
void setTTDisabled (bool disable)
void setPendingTTLoadFile (const std::string &file)

Private Member Functions

void handleUci ()
void handleIsReady ()
void handleSetOption (std::istringstream &is)
void handleUciNewGame ()
void handlePosition (std::istringstream &is)
void handleGo (std::istringstream &is)
void handlePonderHit ()
void handleStop ()
void handleQuit ()
void handleEval ()
void initializeEngine ()
void sendInfo (int depth, int score, int nodes, int nps, const std::vector< Move > &pv, const Board &board)
void sendBestMove (Move move, Move ponderMove=Move(Move::NO_MOVE))
void saveTTSnapshotForMove (const std::string &moveUci)

Static Private Member Functions

static std::string formatScore (int score)
static std::string sanitizeForFilename (const std::string &value)

Private Attributes

std::vector< std::unique_ptr< Evaluator > > evaluators_
std::vector< std::unique_ptr< IEvaluator > > evalCtxs_
TranspositionTable tt_
std::unique_ptr< PolyglotBookbook_
std::vector< std::thread > threadPool_
std::shared_ptr< SearchSharedDatasearchData_
std::unique_ptr< ISearchsearcher_
std::thread searchThread_
std::atomic< bool > searchRunning_ {false}
std::atomic< bool > searchMayRunForever_ {false}
std::atomic< bool > pondering_ {false}
std::atomic< bool > ponderResultReady_ {false}
Move ponderResultMove_ {}
Move ponderMove_ {}
 Expected opponent reply (2nd move in PV).
SearchParams ponderParams_ {}
 Time params from go ponder for ponderhit use.
std::mutex ponderMutex_
Board currentBoard_
UciOptions options_
std::unique_ptr< PolyglotBookbook2_
int consecutiveBookMisses_ = 0
std::string pendingTTLoadFile_
uint64_t ttSnapshotCounter_ = 0
uint64_t searchBaseFullRebuilds_ = 0
uint64_t searchBaseTbHits_ = 0
uint64_t searchBaseTtHits_ = 0

Static Private Attributes

static constexpr const char * ENGINE_NAME = "io-chess-engine"
static constexpr const char * ENGINE_AUTHOR = "Alessandro Gobbetti!"
static constexpr int MAX_BOOK_MISSES = 3

Detailed Description

Main engine controller implementing the UCI protocol.

Orchestrates parsing input from standard input, managing engine options, starting/stopping search threads, and reporting results to standard output.

Constructor & Destructor Documentation

◆ UciProtocol()

UciProtocol::UciProtocol ( const std::string & modelPath,
bool useSimpleEval = false,
const std::string & tbPath = "",
const std::string & bookPath = "",
const std::string & bookPath2 = "",
int evalThreads = 0 )
explicit

Constructs the UCI Protocol handler.

Here is the call graph for this function:

◆ ~UciProtocol()

UciProtocol::~UciProtocol ( )

Member Function Documentation

◆ formatScore()

std::string UciProtocol::formatScore ( int score)
staticprivate
Here is the caller graph for this function:

◆ handleEval()

void UciProtocol::handleEval ( )
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleGo()

void UciProtocol::handleGo ( std::istringstream & is)
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleIsReady()

void UciProtocol::handleIsReady ( )
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handlePonderHit()

void UciProtocol::handlePonderHit ( )
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handlePosition()

void UciProtocol::handlePosition ( std::istringstream & is)
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleQuit()

void UciProtocol::handleQuit ( )
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleSetOption()

void UciProtocol::handleSetOption ( std::istringstream & is)
private
Here is the caller graph for this function:

◆ handleStop()

void UciProtocol::handleStop ( )
private
Here is the caller graph for this function:

◆ handleUci()

void UciProtocol::handleUci ( )
private
Here is the caller graph for this function:

◆ handleUciNewGame()

void UciProtocol::handleUciNewGame ( )
private
Here is the caller graph for this function:

◆ initializeEngine()

void UciProtocol::initializeEngine ( )
private
Here is the caller graph for this function:

◆ initTablebase()

void UciProtocol::initTablebase ( )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ loadBooks()

void UciProtocol::loadBooks ( )
Here is the caller graph for this function:

◆ loop()

void UciProtocol::loop ( )

The main blocking loop that reads commands from standard input.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reinitEngine()

void UciProtocol::reinitEngine ( )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ resizeHash()

void UciProtocol::resizeHash ( size_t mb)
Here is the caller graph for this function:

◆ sanitizeForFilename()

std::string UciProtocol::sanitizeForFilename ( const std::string & value)
staticprivate
Here is the caller graph for this function:

◆ saveTTSnapshotForMove()

void UciProtocol::saveTTSnapshotForMove ( const std::string & moveUci)
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendBestMove()

void UciProtocol::sendBestMove ( Move move,
Move ponderMove = Move(Move::NO_MOVE) )
private
Here is the caller graph for this function:

◆ sendInfo()

void UciProtocol::sendInfo ( int depth,
int score,
int nodes,
int nps,
const std::vector< Move > & pv,
const Board & board )
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setPendingTTLoadFile()

void UciProtocol::setPendingTTLoadFile ( const std::string & file)
inline
Here is the caller graph for this function:

◆ setTTDisabled()

void UciProtocol::setTTDisabled ( bool disable)
Here is the caller graph for this function:

◆ updateEvalContexts()

void UciProtocol::updateEvalContexts ( )
Here is the caller graph for this function:

◆ updateThreads()

void UciProtocol::updateThreads ( int numThreads)
Here is the caller graph for this function:

Member Data Documentation

◆ book2_

std::unique_ptr<PolyglotBook> UciProtocol::book2_
private

◆ book_

std::unique_ptr<PolyglotBook> UciProtocol::book_
private

◆ consecutiveBookMisses_

int UciProtocol::consecutiveBookMisses_ = 0
private

◆ currentBoard_

Board UciProtocol::currentBoard_
private

◆ ENGINE_AUTHOR

const char* UciProtocol::ENGINE_AUTHOR = "Alessandro Gobbetti!"
staticconstexprprivate

◆ ENGINE_NAME

const char* UciProtocol::ENGINE_NAME = "io-chess-engine"
staticconstexprprivate

◆ evalCtxs_

std::vector<std::unique_ptr<IEvaluator> > UciProtocol::evalCtxs_
private

◆ evaluators_

std::vector<std::unique_ptr<Evaluator> > UciProtocol::evaluators_
private

◆ MAX_BOOK_MISSES

int UciProtocol::MAX_BOOK_MISSES = 3
staticconstexprprivate

◆ options_

UciOptions UciProtocol::options_
private

◆ pendingTTLoadFile_

std::string UciProtocol::pendingTTLoadFile_
private

◆ pondering_

std::atomic<bool> UciProtocol::pondering_ {false}
private

◆ ponderMove_

Move UciProtocol::ponderMove_ {}
private

Expected opponent reply (2nd move in PV).

◆ ponderMutex_

std::mutex UciProtocol::ponderMutex_
private

◆ ponderParams_

SearchParams UciProtocol::ponderParams_ {}
private

Time params from go ponder for ponderhit use.

◆ ponderResultMove_

Move UciProtocol::ponderResultMove_ {}
private

◆ ponderResultReady_

std::atomic<bool> UciProtocol::ponderResultReady_ {false}
private

◆ searchBaseFullRebuilds_

uint64_t UciProtocol::searchBaseFullRebuilds_ = 0
private

◆ searchBaseTbHits_

uint64_t UciProtocol::searchBaseTbHits_ = 0
private

◆ searchBaseTtHits_

uint64_t UciProtocol::searchBaseTtHits_ = 0
private

◆ searchData_

std::shared_ptr<SearchSharedData> UciProtocol::searchData_
private

◆ searcher_

std::unique_ptr<ISearch> UciProtocol::searcher_
private

◆ searchMayRunForever_

std::atomic<bool> UciProtocol::searchMayRunForever_ {false}
private

◆ searchRunning_

std::atomic<bool> UciProtocol::searchRunning_ {false}
private

◆ searchThread_

std::thread UciProtocol::searchThread_
private

◆ threadPool_

std::vector<std::thread> UciProtocol::threadPool_
private

◆ tt_

TranspositionTable UciProtocol::tt_
private

◆ ttSnapshotCounter_

uint64_t UciProtocol::ttSnapshotCounter_ = 0
private

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