2 个不稳定版本

0.2.0 2024 年 5 月 27 日
0.1.0 2024 年 4 月 3 日

#92 in 游戏

Download history 125/week @ 2024-05-24 21/week @ 2024-05-31 7/week @ 2024-06-07 3/week @ 2024-06-14 1/week @ 2024-07-05 88/week @ 2024-07-26 8/week @ 2024-08-02

96 每月下载量

Apache-2.0

79KB
1K SLoC

ataxx

Build Status License Crates.io

ataxx 是一个 Rust 包,它提供各种功能来处理纯 Rust 中的 Ataxx 游戏。它提供各种功能,如棋盘表示、走法生成、UAI 客户端创建等。

use ataxx::*;
use std::str::FromStr;

fn main() {
    let position = Position::from_str("x5o/7/7/7/7/7/o5x x 0 1").unwrap();

    println!("{}\n", position);
    println!("perft(6): {}", perft(position, 6));
}

// An implementation of the standard perft function which walks the move
// generation tree of strictly legal moves to count all the leaf nodes of a
// certain depth. Nodes are only counted at the end after the last make-move.
// Thus "higher" terminal nodes (e.g. mate or stalemate) are not counted,
// instead the number of move paths of a certain depth. Perft ignores draws by
// repetition or by the fifty-move rule.
//
// A more advanced implementation of perft is available as `ataxx::perft`.
fn perft(position: Position, depth: u8) -> u64 {
    // perft(0) = 1
    if depth == 0 {
        return 1;
    }

    // perft(1) = number of moves in the position
    if depth == 1 {
        // Counting the number of moves in a Position is provided as a separate
        // function which is faster than the simple `generate_moves.len()`.
        return position.count_moves() as u64;
    }

    let mut nodes: u64 = 0;
    let movelist = position.generate_moves();

    // MoveList implements IntoIterator, so it can be directly used in a for loop.
    for m in movelist {
        // Providing false as the value of the `UPDATE_HASH` template constant
        // disables updating the position's Hash in `after_move` which makes
        // it faster than `after_move::<true>()` and can be done here since we
        // don't use the position's Hash anywhere.
        let new_position = position.after_move::<false>(m);
        nodes += perft(new_position, depth - 1);
    }

    nodes
}

功能

  • 快速的棋盘表示和走法生成,比 libataxx 更快的 perft。
  • Ataxx 的各种功能的类型,包括 PositionMoveSquarePiece 等。
  • 支持 Ataxx 位置的半唯一哈希,用于哈希表,比 zobrist 哈希更快但同样强大。
  • 将 FEN 字符串解析为 Position

有关功能和方法的全列表,请参阅 文档

依赖关系

~0.4–1MB
~21K SLoC