UCILoader 1.1.2
Small C++ library that allows user to connect to a chess engines via UCI protocol.
Loading...
Searching...
No Matches
UCILoader::SearchConnection< Move > Class Template Reference

Manages and controls an ongoing chess engine search operation. More...

#include <EngineConnection.h>

Classes

class  ResultNotReadyException
 Exception thrown when attempting to retrieve results before search completes. More...
 

Public Member Functions

 SearchConnection (std::shared_ptr< ProcessWrapper > engine)
 Constructor for SearchConnection.
 
SearchStatusCode getStatus ()
 Get the current status of the search operation.
 
const SearchResult< Move > & getResult ()
 Retrieve the search result.
 
void stop ()
 Send a stop command to halt the engine's search.
 
void ponderhit ()
 Send a ponderhit command to the engine.
 
void waitFor (const std::chrono::milliseconds &time)
 Block until the search completes or timeout expires.
 
void timeOutIfNotFinished ()
 Set status to TimedOut if search is still ongoing.
 

Detailed Description

template<class Move>
class UCILoader::SearchConnection< Move >

Manages and controls an ongoing chess engine search operation.

Template Parameters
MoveThe move type used by the chess engine

SearchConnection provides a handle to an active search, allowing the user to:

  • Monitor search progress and status
  • Stop or pause the search
  • Retrieve results when ready
  • Implement timeouts

Instances are typically obtained by calling the search() method on an EngineInstance. The SearchConnection takes ownership of the search and manages its lifecycle.

See also
EngineInstance::search() for initiating a search
SearchStatusCode for understanding search states

Constructor & Destructor Documentation

◆ SearchConnection()

template<class Move >
UCILoader::SearchConnection< Move >::SearchConnection ( std::shared_ptr< ProcessWrapper engine)
inline

Constructor for SearchConnection.

Parameters
engineShared pointer to the engine process

Member Function Documentation

◆ getResult()

template<class Move >
const SearchResult< Move > & UCILoader::SearchConnection< Move >::getResult
inline

Retrieve the search result.

Returns
Const reference to the SearchResult containing bestMove and ponderMove
Exceptions
ResultNotReadyExceptionif the search status is not ResultReady

Always call getStatus() first to verify the status is ResultReady before calling this method. This avoids potential ResultNotReadyException thrown when results are not yet available.

◆ getStatus()

template<class Move >
SearchStatusCode UCILoader::SearchConnection< Move >::getStatus
inline

Get the current status of the search operation.

Returns
The current SearchStatusCode

◆ ponderhit()

template<class Move >
void UCILoader::SearchConnection< Move >::ponderhit
inline

Send a ponderhit command to the engine.

Instructs the engine to switch from pondering mode to active searching. This is a no-op if the search status is not OnGoing. The search status remains unchanged regardless of whether the command is sent.

◆ stop()

template<class Move >
void UCILoader::SearchConnection< Move >::stop
inline

Send a stop command to halt the engine's search.

Sets search status to Stopped unless already in a final state (ResultReady or Terminated). This is a no-op if the search has already completed or been terminated. However, for TimedOut status, stop will still be sent to terminate the engine's ongoing work.

◆ timeOutIfNotFinished()

template<class Move >
void UCILoader::SearchConnection< Move >::timeOutIfNotFinished
inline

Set status to TimedOut if search is still ongoing.

This is intended for asynchronous use cases where the caller manages timeouts manually instead of using the waitFor() method. If status is already in a final state, this is a no-op.

◆ waitFor()

template<class Move >
void UCILoader::SearchConnection< Move >::waitFor ( const std::chrono::milliseconds &  time)
inline

Block until the search completes or timeout expires.

The calling thread will be suspended and woken when:

  • Search completes with a bestmove result
  • Engine crashes or terminates
  • The specified timeout duration expires

If the engine doesn't deliver bestmove before timeout, status will be set to TimedOut.

Parameters
timeMaximum duration to wait in milliseconds
See also
getStatus() to check the final status after waiting

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