Crate shakmaty

Crate shakmaty 

Source
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 yet

Also supports FEN, SAN and UCI formats for positions and moves.

§Feature flags

  • alloc: Enables APIs which require the alloc crate (e.g. FEN string rendering).

  • std: Implies alloc. Enabled by default. For no_std environments, this must be disabled with default-features = false.

  • variant: Enables support for all Lichess variants.

  • arbitrary: Implements arbitrary::Arbitrary for vocabulary types.

  • bincode: Implements bincode encoding/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: Implements serde serialization/deserialization for types with unique natural representations.

  • nohash-hasher: Implements nohash_hasher::IsEnabled for sensible types.

Re-exports§

pub use bitboard::Bitboard;
pub use board::Board;

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.
variantvariant
Chess variants.
zobrist
Zobrist hashing for positions.

Structs§

ByCastlingSide
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.
ParseColorError
Error when parsing an invalid color name.
ParseOutcomeError
Error when parsing an Outcome or KnownOutcome.
ParseSquareError
Error when parsing an invalid square name.
Piece
A piece with Color and Role.
PlayError
Error when trying to play an illegal move.
PositionError
Error when trying to create a Position from an illegal Setup.
PositionErrorKinds
Reasons for a Setup not being a legal Position.
RemainingChecks
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§

CastlingMode
Standard or Chess960.
CastlingSide
KingSide (O-O) or QueenSide (O-O-O).
Color
White or Black.
EnPassantMode
When to include the en passant square.
File
A file of the chessboard.
KnownOutcome
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§

FromSetup
Validate and set up a playable Position. All provided chess variants support this.
Position
A playable chess or chess variant position. See Chess for a concrete implementation.

Functions§

perft
Counts legal move paths of a given length.

Type Aliases§

MoveList
A container for moves that can be stored inline on the stack.