Expand description
A library for chess vocabulary and move generation.
§Examples
Generate legal moves in the starting position:
use shakmaty::{Chess, Position};
let pos = Chess::default();
let legals = pos.legal_moves();
assert_eq!(legals.len(), 20);Play moves:
use shakmaty::{Square, Move, Role};
// 1. e4
let pos = pos.play(Move::Normal {
role: Role::Pawn,
from: Square::E2,
to: Square::E4,
capture: None,
promotion: None,
})?;Detect game end conditions:
assert!(!pos.is_checkmate());
assert!(!pos.is_stalemate());
assert!(!pos.is_insufficient_material());
assert_eq!(pos.outcome(), Outcome::Unknown); // no winner yetAlso supports FEN, SAN and UCI formats for positions and moves.
§Feature flags
-
alloc: Enables APIs which require thealloccrate (e.g. FEN string rendering). -
std: Impliesalloc. Enabled by default. Forno_stdenvironments, this must be disabled withdefault-features = false. -
variant: Enables support for all Lichess variants. -
arbitrary: Implementsarbitrary::Arbitraryfor vocabulary types. -
bincode: Implementsbincodeencoding/decoding for vocabulary types.Changing encodings is considered a semver breaking change and will be noted in the changelog. But note that in such a case a migration by unpacking with the previous version may be required.
-
serde: Implementsserdeserialization/deserialization for types with unique natural representations. -
nohash-hasher: Implementsnohash_hasher::IsEnabledfor sensible types.
§Related crates
Re-exports§
Modules§
- attacks
- Attack and ray tables.
- bitboard
- Sets of squares.
- board
- Piece positions on a board.
- fen
- Parse and write Forsyth-Edwards-Notation.
- packed
- Binary encodings that balance compression and encoding/decoding speed.
- san
- Read and write Standard Algebraic Notation.
- uci
- Parse and write moves in Universal Chess Interface representation.
- variant
variant - Chess variants.
- zobrist
- Zobrist hashing for positions.
Structs§
- ByCastling
Side - Container with values for each
CastlingSide. - ByColor
- Container with values for each
Color. - ByRole
- Container with values for each
Role. - Castles
- Castling paths and unmoved rooks.
- Chess
- A standard Chess position.
- Parse
Color Error - Error when parsing an invalid color name.
- Parse
Outcome Error - Error when parsing an
OutcomeorKnownOutcome. - Parse
Square Error - Error when parsing an invalid square name.
- Piece
- A piece with
ColorandRole. - Play
Error - Error when trying to play an illegal move.
- Position
Error - Error when trying to create a
Positionfrom an illegalSetup. - Position
Error Kinds - Reasons for a
Setupnot being a legalPosition. - Remaining
Checks - The number of checks the respective side needs to give in order to win (in a game of Three-Check).
- Setup
- A not necessarily legal position.
Enums§
- Castling
Mode StandardorChess960.- Castling
Side KingSide(O-O) orQueenSide(O-O-O).- Color
WhiteorBlack.- EnPassant
Mode - When to include the en passant square.
- File
- A file of the chessboard.
- Known
Outcome - A definitive outcome of a game.
- Move
- Information about a move.
- Outcome
- Outcome of a game, if any.
- Rank
- A rank of the chessboard.
- Role
- Piece types:
Pawn,Knight,Bishop,Rook,Queen,King. - Square
- A square of the chessboard.
Traits§
- From
Setup - Validate and set up a playable
Position. All provided chess variants support this. - Position
- A playable chess or chess variant position. See
Chessfor a concrete implementation.
Functions§
- perft
- Counts legal move paths of a given length.
Type Aliases§
- Move
List - A container for moves that can be stored inline on the stack.