Expand description
§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_stdcompatible- 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
BitBoardusesu128instead ofu64as 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 theErrortrait.
§Installation
Add haitaka to your Cargo.toml:
[dependencies]
haitaka = "0.2.1" # 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 used in a Shogi engine, so should still be seen as experimental.
To run all tests use:
cargo test§Contributing
Contributions are very welcome! Please open an issue or submit a pull request on GitHub.
§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.
§References
§Examples
This crate also includes some examples that illustrate the API and can be used as tools. You can find them in the
examples directory of the repository:
- Find Magics Generates magic numbers for slider moves.
- Perft A perft implementation for Shogi.
To run an example, clone the reposity and use one of the following commands:
cargo run --release --example find_magics -- --verbose
cargo run --release --example perft -- 3Re-exports§
pub use attacks::*;pub use board::*;pub use slider_moves::*;
Modules§
- attacks
- Pseudo-attacks for non-sliding pieces
- board
- The Shogi
Boardrepresentation and move generation functions - slider_
moves - Slider
Macros§
Structs§
- BitBoard
- A bitboard.
A bitboard is an ordered set of squares. The set contains a square if bit
1 << square as usizeis set. - BitBoard
Iter - An iterator over the squares of a bitboard.
- BitBoard
Subset Iter - An iterator over the subsets of a bitboard.
- Color
Parse Error - The value was not a valid
Color. - Colored
Piece - File
Parse Error - The value was not a valid
File. - Piece
Parse Error - The value was not a valid
Piece. - Rank
Parse Error - The value was not a valid
Rank. - Square
Parse Error - The value was not a valid
Square.
Enums§
- Color
- A side to move.
- File
- A file (column) on a shogi board.
- Move
- A Shogi move.
- Move
Parse Error - The value was not a valid
Move. - Piece
- Shogi piece types.
- Rank
- A rank (row) on a shogi board.
- Square
- A square on a Shogi board.
Constants§
- BISHOP_
TABLE_ SIZE - NEG_DIA
- Up-slanting diagonals.
- POS_DIA
- Down-slanting diagonals.
- ROOK_
TABLE_ SIZE - SLIDING_
MOVES_ TABLE_ SIZE
Functions§
- bishop_
pseudo_ attacks - Bishop pseudo-attacks.
- drop_
zone - Returns a BitBoard representing all squares where a piece may
be dropped. This is the inverse of
no_fly_zone. - get_
between_ rays - Get all squares between two squares, if reachable via a ray.
The
fromandtosquare are not included in the returnsBitBoard. - get_
bishop_ moves_ index - get_
bishop_ moves_ slow - get_
bishop_ relevant_ blockers - Get Bishop blocker mask.
- get_
lance_ moves - Return a BitBoard with pseudo-legal lance moves.
- get_
lance_ moves_ slow - get_
lance_ relevant_ blockers - Get Lance blocker mask.
- get_
rook_ file_ moves - Return a BitBoard of Rook moves on its file, up to the first blocking pieces (if any).
- get_
rook_ moves_ index - get_
rook_ moves_ slow - get_
rook_ rank_ moves - Return a BitBoard of Rook moves on its rank, up to the first blocking pieces (if any).
- get_
rook_ relevant_ blockers - Returns the Rook blocker mask for the given square.
- lance_
pseudo_ attacks - Lance pseudo-attacks.
- line_
ray - Get a ray on the board that passes through both squares, if it exists.
- must_
prom_ zone - Returns a
BitBoardof all squares where the piece must promote. - no_
fly_ zone - Get the no-fly-zones for a piece.
- prom_
zone - Returns a
BitBoardrepresenting the promotion zone for the color. - rook_
pseudo_ attacks - Rook pseudo-attacks from square.