3 unstable releases
Uses new Rust 2024
new 0.2.1 | Apr 14, 2025 |
---|---|
0.2.0 | Apr 10, 2025 |
0.1.0 | Apr 5, 2025 |
#78 in Games
284 downloads per month
270KB
4.5K
SLoC
haitaka
ハイタカ
Rust Shogi move generation library
haitaka
is a Shogi move generation library written in Rust that aims to support fast move generation.
It is inspired by the beautifully designed cozy-chess
library written by analog-hors
.
The layout of the modules and the overall design is largely the same as in cozy-chess
. Many low-level functions were copied from cozy-chess
, with only trivial modifications, but since there are significant differences between Shogi and International Chess, I also modified some of the higher-level functions and added extra functionality.
Name
"Haitaka" or "taka" means "sparrowhawk" in Japanese. "Taka" is a haiku kigo (season word) associated with winter.
鷹の眼にこぼれて雁のたち騒ぐ
Taka no me ni koborete kari no tachisawagu
Escaping the hawk's eye,
the wild geese
rise in tumult.
-— 加賀千代女 (Kaga no Chiyojo)
Overview
no_std
compatible- Strongly-typed API that makes heavy use of newtypes to avoid errors
- Efficient bitboard-based board representation
- Performant legal move generation
- Incrementally updated zobrist hash for quickly obtaining a hash of a board
- Supporting both Magic Bitboards and the Qugiy algorithm for slider move generation
- Support for parsing SFEN strings
Main differences with cozy-chess
BitBoard
usesu128
instead ofu64
as backing to handle the 9x9 Shogi board- Move generation handles both board moves and drops
- Move generation of sliders also implements the Qugiy algorithm
- File-major ordering of squares to make move generation faster
Crate features
std
: Enable features that requirestd
. Currently only used for theError
trait.
Installation
Add haitaka
to your Cargo.toml
:
[dependencies]
haitaka = "0.2.0" # or use the latest version on crates.io
Usage
Basic
use haitaka::*;
// Start position
let board = Board::startpos();
let mut move_list = Vec::new();
board.generate_moves(|moves| {
// Unpack into move list
move_list.extend(moves);
false
});
assert_eq!(move_list.len(), 30);
Perft
cargo run --release --example perft -- 5
Testing
This code has been tested on an Apple M2, using the stable-aarch64-apple-darwin toolchain. In GitHub workflows it has also been tested on Ubuntu.
The code has not yet been stress tested yet or used in an actual Shogi engine.
To run all tests use:
cargo test
Acknowledgments
Portions of this library are derived from the cozy-chess
project by analog-hors
. The cozy-chess
project is licensed under the MIT license, and its license text is included in this repository under third_party/cozy-chess/LICENSE
.