#棋引擎 #棋类 #UCI #引擎 #包装器

uciengine

使用支持uci命令的棋引擎包装器,这些命令对于玩游戏是必要的。不支持分析。

33个版本

0.1.33 2021年2月2日
0.1.32 2021年2月1日
0.1.30 2021年1月30日

#1239 in 游戏开发

Download history 88/week @ 2024-03-31 1/week @ 2024-04-07

118 每月下载量
用于 lichessbot

MIT 许可证

45KB
887 代码行

uciengine

documentation Crates.io Crates.io (recent)

Rust UCI棋引擎包装器。实现了UCI协议的有用部分( http://wbec-ridderkerk.nl/html/UCIProtocol.html )。允许从并行异步中进行多次搜索。搜索是排队进行的,并以对结果接收者透明的方式逐个完成。该crate的主要目标是支持游戏模式。不支持分析模式/搜索时的流结果。您发出go / ponderhit / pondermiss命令,并等待bestmove / ponder。 (Pondermiss是该crate用来表示已等待的停止命令的一个花哨名称,以反映失败ponder的使用场景。)

用法

extern crate env_logger;

use uciengine::uciengine::*;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    env_logger::init();

    let go_job1 = GoJob::new()
        .uci_opt("UCI_Variant", "atomic")
        .uci_opt("Hash", 128)
        .uci_opt("Threads", 4)
        .pos_fen("k7/8/8/8/8/8/R7/7K w - - 0 1")
        .pos_moves("h1h2")
        .tc(Timecontrol {
            wtime: 15000,
            winc: 0,
            btime: 15000,
            binc: 0,
        });

    let go_job2 = GoJob::new()
        .uci_opt("UCI_Variant", "chess")
        .pos_startpos()
        .go_opt("depth", 12);

    let engine = UciEngine::new("./stockfish12");

    // make two clones of the engine, so that we can move them to async blocks
    let (engine_clone1, engine_clone2) = (engine.clone(), engine.clone());

    // issue two parallel async go commands, to demonstrate that they will be queued and processed one a time
    tokio::spawn(async move {
        let go_result1 = engine_clone1.go(go_job1).await;

        println!("go result 1 {:?}", go_result1);
    });

    tokio::spawn(async move {
        let go_result2 = engine_clone2.go(go_job2).await;

        println!("go result 2 {:?}", go_result2);
    });

    // wait enough for the go commands to complete in the background
    tokio::time::sleep(tokio::time::Duration::from_millis(20000)).await;

    // quit engine
    engine.quit();

    // wait for engine to quit gracefully
    tokio::time::sleep(tokio::time::Duration::from_millis(3000)).await;

    Ok(())
}

日志记录

export RUST_LOG=info
# or
export RUST_LOG=debug

依赖

~3–10MB
~92K SLoC