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§
- Analysis
Request - A game record to be analyzed, along with analysis settings.
- Analysis
Response - The result of analyzing a position.
- Engine
- An instance of the KataGo analysis engine, launched as a child process.
- Engine
Stdin - Sends requests to the analysis engine.
- Launch
Options - Command line options for launching KataGo.
- Move
Info - The result of analyzing a candidate move.
- Restricted
Moves - A list of moves that are either forbidden with
AnalysisRequest::avoid_movesor allowed withAnalysisRequest::allow_moves. - Root
Info - The result of analyzing the root position.
Enums§
Type Aliases§
- Engine
Stdout - A
StreamofResponses from the analysis engine.