Crates.io | pyrrhic-rs |
lib.rs | pyrrhic-rs |
version | 0.2.0 |
source | src |
created_at | 2024-03-26 18:07:28.546276 |
updated_at | 2024-03-28 20:44:01.379045 |
description | A pure-Rust library to probe Syzygy Tablebases within a chess engine |
homepage | |
repository | https://github.com/Algorhythm-sxv/pyrrhic-rs |
max_upload_size | |
id | 1186770 |
size | 136,048 |
pyrrhic-rs
is a library for use in chess engines to probe the Syzygy endgame tablesbases during a search.
Pyrrhic's original API is unsafe, with potential for memory corruption if used improperly. Therefore pyrrhic-rs
wraps this unsafe API in the TableBases
struct, which guards against memory- and thread-unsafe usage of the Pyrrhic API.
As pyrrhic-rs
is designed to be used within an existing engine, the user must implement the EngineAdapter
trait on a type for the probing code to be able to use the engine's own move generation code. Afterwards, Tablebases::new()
can be called using this type as a parameter.
cozy_chess
:use cozy_chess::*;
struct CozyChessAdapter;
impl EngineAdapter for CozyChessAdapter {
fn pawn_attacks(color: pyrrhic_rs::Color, sq: u64) -> u64 {
let attacks = get_pawn_attacks(
Square::index(sq as usize),
if color == pyrrhic_rs::Color::Black {
Color::Black
} else {
Color::White
},
);
attacks.0
}
fn knight_attacks(sq: u64) -> u64 {
get_knight_moves(Square::index(sq as usize)).0
}
fn bishop_attacks(sq: u64, occ: u64) -> u64 {
get_bishop_moves(Square::index(sq as usize), BitBoard(occ)).0
}
fn rook_attacks(sq: u64, occ: u64) -> u64 {
get_rook_moves(Square::index(sq as usize), BitBoard(occ)).0
}
fn king_attacks(sq: u64) -> u64 {
get_king_moves(Square::index(sq as usize)).0
}
fn queen_attacks(sq: u64, occ: u64) -> u64 {
(get_bishop_moves(Square::index(sq as usize), BitBoard(occ))
| get_rook_moves(Square::index(sq as usize), BitBoard(occ)))
.0
}
}
fn main() {
let tb = pyrrhic_rs::TableBases::<CozyChessAdapter>::new("./syzygy/tb345:./syzygy/tb6:./syzygy/tb7").unwrap();
}
pyrrhic-rs
was initially transliterated from the original Pyrrhic library in C, and is therefore subject to the following copyrights: