Skip to content

Repository files navigation

rsshogi-usi

crates.io | docs.rs | Documentation | MIT License

将棋エンジンで共有しやすい USI protocol surface を提供する Rust crate です。 USI command model、parser、formatter を engine 固有ロジックから切り離し、 GUI と engine 間の line I/O を安定して実装しやすくします。

主な機能

  • Command model: UsiCommand, GoParams, InfoCommand, PositionSpec などの型付き surface
  • Parser: GUI→Engine / Engine→GUI の USI line を parse
  • Formatter: command model から canonical な USI line を出力
  • Mate line helpers: GoMate, GoParams, CheckmateResponse, UsiCommand から go mate / checkmate を組み立てやすい
  • Diagnostics: parse failure に token / byte 位置 metadata を付けて consumer 側の調査を助ける
  • Position replay helper: PositionSpec + moves を engine-agnostic な callback で replay できる
  • Portability checks: validate_portable_command で ShogiHome など単一 token 前提 GUI へ出す line を事前確認できる
  • 互換性保持: engine 固有 token は stringly な拡張 surface に残し、protocol crate に取り込みすぎない
  • Transcript coverage: roundtrip と compatibility を transcript test で固定

インストール

cargo add rsshogi-usi
[dependencies]
rsshogi-usi = "0.2.0"

クイックスタート

use rsshogi_usi::{format_command, parse_line, UsiCommand};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let command = parse_line("position startpos moves 7g7f 3c3d")?;

    match command {
        UsiCommand::Position { spec, moves } => {
            let canonical = format_command(&UsiCommand::Position { spec, moves });
            println!("{canonical}");
        }
        _ => unreachable!(),
    }

    Ok(())
}

対応 surface

  • GUI→Engine: usi, isready, setoption, position, go, stop, ponderhit, quit, usinewgame, gameover
  • Engine→GUI: id, option, usiok, readyok, info, bestmove, checkmate
  • 拡張 command: eval, test_movegen, test_see, ponderhit ... (ShogiHome early ponder 互換入力)

ドキュメント

rshogi-usi からの移行

このcrateはrshogi-usiの後継です。dependency名とRust import名を次のように変更してください。

-rshogi-usi = "0.1.6"
+rsshogi-usi = "0.2.0"
-use rshogi_usi::{format_command, parse_line, UsiCommand};
+use rsshogi_usi::{format_command, parse_line, UsiCommand};

公開APIとprotocol behaviorはrshogi-usi 0.1.6を引き継いでいます。 rsshogiへのdependencyは持たず、engine-agnosticなprotocol crateとして独立しています。

ライセンス

MIT License

About

Engine-agnostic USI protocol command model, parser, and formatter

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages