Skip to main content

Module engine

Module engine 

Source
Expand description

KataGo’s analysis protocol, implemented as a low-level stream of unsynchronized messages.

See KataGo Parallel Analysis Engine for official documentation of the analysis engine.

You probably want to use the higher-level API in the crate root instead of this module. This module is intended for use cases that require lower-level control over the messages sent to and received from the engine.

Note: The asynchronous methods in this library must be called from within a Tokio runtime.

§Example

use katago_analysis::{
    Player, Result, Rules,
    engine::{AnalysisRequest, AnalysisResponse, Engine, LaunchOptions, Request, Response},
};
use tokio_stream::StreamExt;

async fn example(
    katago_path: String,
    analysis_config_path: String,
    model_path: String,
) -> Result<()> {
    let options = LaunchOptions::new(katago_path, analysis_config_path, model_path);
    let mut engine = Engine::launch(&options)?;

    let request = AnalysisRequest::new(
        "1".to_string(),
        Rules::chinese(),
        19,
        19,
        vec![
            (Player::Black, "Q16".to_string()),
            (Player::White, "D4".to_string()),
        ],
    );
    engine.stdin.send(&Request::Analyze(request)).await?;
    match engine.stdout.try_next().await? {
        Some(Response::Analyze(AnalysisResponse { move_infos, .. })) => {
            println!(
                "Best move: {} ({:.1}%)",
                move_infos[0].mv,
                move_infos[0].winrate * 100.0
            );
            println!("{:?}", move_infos[0]);
        }
        _ => println!("Something went wrong"),
    };
    Ok(())
}

Structs§

AnalysisRequest
A game record to be analyzed, along with analysis settings.
AnalysisResponse
The result of analyzing a position.
Engine
An instance of the KataGo analysis engine, launched as a child process.
EngineStdin
Sends requests to the analysis engine.
LaunchOptions
Command line options for launching KataGo.
MoveInfo
The result of analyzing a candidate move.
RestrictedMoves
A list of moves that are either forbidden with AnalysisRequest::avoid_moves or allowed with AnalysisRequest::allow_moves.
RootInfo
The result of analyzing the root position.

Enums§

Request
A request to the analysis engine.
Response
A response from the analysis engine.

Type Aliases§

EngineStdout
A Stream of Responses from the analysis engine.