#国际象棋 #PGN #防御 #评论 #语言 #解析器 #功能丰富

bin+lib sacrifice

Rust 的功能丰富的国际象棋库

17 个版本

0.3.0-alpha.32023年10月18日
0.3.0-alpha.22023年10月17日
0.2.0 2023年4月17日
0.1.12 2023年4月11日
0.1.0 2023年3月30日

#352 in 游戏

Download history 94/week @ 2024-03-08 7/week @ 2024-03-29

57 每月下载量

MITGPL-3.0+

41KB
822

sacrifice

crates.io version docs.rs version

基于 crates.io version 的 Rust 功能丰富的国际象棋库。

sac = { package = "sacrifice", version = "0.3.0-alpha.2" }

示例

fn main() {
    let mut game = sac::read_pgn(
        "1. e4 { this blunders into the Sicilian Defense }  1... c5"
    );
    println!("{}", game); // exports the PGN string
  
    let mut root = game.root();

    // Play the Open Sicilian with 2. Nf3
    let open_sicilian = sac::Move::Normal {
        role: sac::Role::Knight,
        from: sac::Square::G1,
        to: sac::Square::F3,
        capture: None,
        promotion: None,
    };
    let mut new_node = root.new_variation(open_sicilian).unwrap(); // 2. Nf3 node
    println!("{}", game); // exports the PGN string after 2. Nf3

    // Take back the previous 2. Nf3 move
    new_node.remove_node();
    println!("{}", game);

    // What if someone want to play 1. d4?
    let queens_pawn = sac::Move::Normal {
        role: sac::Role::Pawn,
        from: sac::Square::D2,
        to: sac::Square::D4,
        capture: None,
        promotion: None,
    };
    let new_node = root.new_variation(queens_pawn); // 1. d4 node
    println!("{}", game); // 1. e4 (1. d4) 1... c5
}

功能

目前,它支持

  • 游戏树遍历
  • PGN 序列/反序列化
  • 评论
  • NAG 符号

依赖关系

~1.5MB
~22K SLoC