Crate shakmaty

source ·
Expand description

A library for chess 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(), None); // 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: Implements the std::error::Error trait for various errors in the crate. Implies the alloc feature (since std depends on alloc anyway). Enabled by default for convenience. For no_std environments, this must be disabled with default-features = false.
  • variant: Enables support for all Lichess variants.
  • nohash-hasher: Implements nohash_hasher::IsEnabled for sensible types.

Re-exports§

Modules§

  • Attack and ray tables.
  • Sets of squares.
  • Piece positions on a board.
  • Parse and write Forsyth-Edwards-Notation.
  • Read and write Standard Algebraic Notation.
  • Parse and write moves in Universal Chess Interface representation.
  • variantvariant
    Chess variants.
  • Zobrist hashing for positions.

Structs§

Enums§

Traits§

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

Functions§

  • Counts legal move paths of a given length.

Type Aliases§

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