|
|
| EngineInstance (std::shared_ptr< ProcessWrapper > engineProcess, std::shared_ptr< Marschaler< Move > > moveMarshaler, std::shared_ptr< PatternMatcher > moveValidator, std::unique_ptr< Logger > &&logger) |
| |
| void | sync (std::chrono::milliseconds timeout=std::chrono::milliseconds(10000)) |
| | Synchronize engine state with local representation.
|
| |
| void | ucinewgame () |
| | Send the ucinewgame command to the engine.
|
| |
| std::chrono::milliseconds | ping (std::chrono::milliseconds timeout=std::chrono::milliseconds(10000)) |
| | Measure engine latency by performing a ping operation.
|
| |
| std::shared_ptr< SearchConnection< Move > > | getCurrentSearch () |
| | Get the currently active search connection.
|
| |
| std::shared_ptr< SearchConnection< Move > > | search (const GoParams< Move > ¶ms, const PositionFormatter &pos, const std::vector< Move > moves={}) |
| | Start a new search operation with specified parameters.
|
| |
| std::string | getName () |
| | Get the engine's name as declared via the id name command.
|
| |
| std::string | getAuthor () |
| | Get the engine author's name as declared via the id author command.
|
| |
| bool | healthCheck () |
| | Check the health status of the underlying engine process.
|
| |
| void | quit () |
| | Manually terminate the engine process.
|
| |
| void | unlink (const EventReceiver *receiver) |
| | Disconnect a specific receiver from future events.
|
| |
| void | connect (std::shared_ptr< EventReceiver > receiver) |
| | Connect a custom event receiver.
|
| |
| void | connect (std::function< void(const EngineEvent *)> callback, uint32_t eventFilter) |
| | Connect a callback function that receives the full event.
|
| |
| void | connect (std::function< void()> callback, uint32_t eventFilter) |
| | Connect a simple parameterless callback function.
|
| |
template<class Move>
class UCILoader::EngineInstance< Move >
Top-level interface for managing and interacting with a UCI chess engine.
- Template Parameters
-
| Move | The move type used by the engine |
EngineInstance is the primary interface for communicating with a chess engine over UCI protocol. It handles:
- Engine initialization and synchronization
- Option management and configuration
- Search operations and result retrieval
- Event emission for status changes
- Graceful shutdown
Typical Usage:
engine->sync();
std::cout << "Engine: " << engine->getName() << std::endl;
if (engine->options.contains("Hash")) {
engine->options["Hash"] = 256;
}
auto search = engine->search(params, position, moves);
search->waitFor(std::chrono::seconds(5));
if (
search->getStatus() == ResultReady) {
auto result =
search->getResult();
std::cout << "Best move: " << moveToString(result.bestMove) << std::endl;
}
std::shared_ptr< SearchConnection< Move > > search(const GoParams< Move > ¶ms, const PositionFormatter &pos, const std::vector< Move > moves={})
Start a new search operation with specified parameters.
Definition: EngineConnection.h:995
const LoggerTrait & Pretty
Trait that formats log messages for human readability.
Definition: Logger.cpp:165
LoggerBuilder toFile(const std::string &filename)
Create a logger that outputs to a file.
Definition: Logger.cpp:185
- Warning
- Always call sync() after construction to ensure engine options and metadata are loaded.
- See also
- EngineInstanceBuilder for creating instances
-
Logger for configuring logging behavior
Manually terminate the engine process.
Note: Manually calling this method is unnecessary. The engine will be automatically terminated when the EngineInstance object goes out of scope via the destructor.
However, manual termination is allowed for exceptional cases, such as when the engine becomes stuck in an infinite loop or is otherwise unresponsive. In such scenarios, calling quit() will forcibly shut down the engine process.
- Warning
- Important: After calling quit() manually, the EngineInstance object becomes unusable. Do not attempt to perform any operations other than health check (search, sync, option configuration, etc.) on the EngineInstance after calling this method.
Synchronize engine state with local representation.
Sends an 'isready' command to the engine and waits for the 'readyok' response. This ensures the engine is responsive and have all options and metadata (name, author) loaded.
This method should be called after constructing an EngineInstance and before performing operations like querying options or starting searches.
- Parameters
-
| timeout | Maximum time to wait for engine response (default 10 seconds) |
- Exceptions
-
If a timeout occurs, the engine process will be terminated and this exception thrown. After a timeout, the EngineInstance should be considered unusable.