Skip to main content

eschac/
lib.rs

1//! # eschac - a library for computing chess moves
2//!
3//! eschac implements fast legal move generation and a copy-make interface that enforces at compile
4//! time that no illegal move is played, with no runtime checks and no potential panics.
5//!
6//! ## Overview
7//!
8//! In eschac, a chess position is represented with the [`Position`](position::Position) type.
9//! [`Position::new`](position::Position::new) returns the starting position of a chess game, and
10//! arbitrary positions can be built using the [`Setup`](setup::Setup) type. This type must be
11//! validated and converted to [`Position`](position::Position) with
12//! [`Setup::into_position`](setup::Setup::into_position). Legal moves are generated using the
13//! [`Position::legal_moves`](position::Position::legal_moves) method or obtained from chess
14//! notation like [`UciMove`](uci::UciMove) or [`San`](san::San). Moves are represented with the
15//! [`Move<'l>`](position::Move) type, which holds a reference to the origin position to ensure
16//! that the move is not played on another one. Finally, moves are played with
17//! [`Move::make`](position::Move::make) which returns a new [`Position`](position::Position), and
18//! on it goes.
19//!
20//! ## Example
21//!
22//! ```
23//! # (|| -> Result<(), Box<dyn std::error::Error>> {
24//!
25//! use eschac::prelude::*;
26//!
27//! // read a position from a text record
28//! let setup = Setup::from_text_record("7k/4P1rp/5Q2/5p2/1Pp1bP2/8/r4K1P/6R1 w - -")?;
29//! let position = setup.into_position()?;
30//!
31//! // read a move in algebraic notation
32//! let san = "Ke1".parse::<San>()?;
33//! let m = san.to_move(&position)?;
34//!
35//! // play the move (note the absence of error handling)
36//! let position = m.make();
37//!
38//! // generate all the legal moves on the new position
39//! let moves = position.legal_moves();
40//! for m in moves {
41//!     // print the UCI notation of each move
42//!     println!("{}", m.to_uci());
43//! }
44//! # Ok(()) });
45//! ```
46//!
47//! ## Comparison with [shakmaty](https://crates.io/crates/shakmaty)
48//!
49//! shakmaty is another Rust library for chess processing. It is written by Niklas Fiekas, whose
50//! work greatly inspired the development of eschac. For most purposes, shakmaty is probably a
51//! better option, as eschac comes short of its miriad of features.
52//!
53//! Both libraries have the same core features:
54//! - vocabulary to describe the chessboard (squares, pieces, etc.)
55//! - parsing and editing positions
56//! - parsing standard move notations
57//! - fast legal move generation and play
58//!
59//! **eschac** distinguishes itself with:
60//! - a focus on performance
61//! - a more compact board representation
62//! - its use of the borrow checker to guarantee only legal moves are played
63//!
64//! **shakmaty** will be more suitable for a lot of applications, with:
65//! - vocabulary to describe and work with games, not just positions
66//! - insufficient material detection
67//! - PGN parsing
68//! - Zobrist hashing
69//! - Syzygy endgame tablebases
70//! - chess960 and other variants
71//! - etc.
72
73#![no_std]
74
75extern crate alloc;
76
77pub(crate) mod array_vec;
78pub(crate) mod iterator;
79pub(crate) mod lookup;
80pub(crate) mod magics;
81
82pub mod bitboard;
83pub mod board;
84pub mod position;
85pub mod san;
86pub mod setup;
87pub mod uci;
88
89/// The eschac prelude.
90pub mod prelude {
91    pub use crate::{
92        bitboard::Bitboard,
93        board::Piece,
94        board::{Castle, Color, File, Rank, Role, Square},
95        position::{Move, Moves, Position, RawMove},
96        san::San,
97        setup::{AsSetup, Setup},
98        uci::UciMove,
99    };
100}