Expand description
§eschac - a library for computing chess moves
eschac implements fast legal move generation and a copy-make interface that enforces at compile time that no illegal move is played, with no runtime checks and no potential panics.
§Overview
In eschac, a chess position is represented with the Position type.
Position::new returns the starting position of a chess game, and
arbitrary positions can be built using the Setup type. This type must be
validated and converted to Position with
Setup::into_position. Legal moves are generated using the
Position::legal_moves method or obtained from chess
notation like UciMove or San. Moves are represented with the
Move<'l> type, which holds a reference to the origin position to ensure
that the move is not played on another one. Finally, moves are played with
Move::make which returns a new Position, and
on it goes.
§Example
use eschac::prelude::*;
// read a position from a text record
let setup = Setup::from_text_record("7k/4P1rp/5Q2/5p2/1Pp1bP2/8/r4K1P/6R1 w - -")?;
let position = setup.into_position()?;
// read a move in algebraic notation
let san = "Ke1".parse::<San>()?;
let m = san.to_move(&position)?;
// play the move (note the absence of error handling)
let position = m.make();
// generate all the legal moves on the new position
let moves = position.legal_moves();
for m in moves {
// print the UCI notation of each move
println!("{}", m.to_uci());
}§Comparison with shakmaty
shakmaty is another Rust library for chess processing. It is written by Niklas Fiekas, whose work greatly inspired the development of eschac. Both libraries have similar base features to handle the chessboard – editing the position & making moves – as well as fast move generation. eschac distinguishes itself with a focus on performance for standard chess, a more compact board representation and its use of the borrow checker. shakmaty on the other hand has a more complex interface that handles chess960 and other variants, and offers more features such as PGN parsing, Zobrist hashing, Syzygy endgame tablebases, and more.
§Feature flags
alloc: Enables interfaces requiring thealloccrate (e.g.Moves::sort_by).std: Impliesalloc. Enabled by default and must be disabled forno_stdenvironments.