Expand description

A library for chess move generation.


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_eq!(pos.outcome(), None); // no winner yet

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

Feature flags

  • variant: Enables shakmaty::variant module for all Lichess variants.
  • step: Implements std::iter::Step for Square, File, and Rank. Requires nightly Rust.


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


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.


Chess variants.

Zobrist hashing for positions.


Container with values for each Color.

Container with values for each Role.

Castling paths and unmoved rooks.

A standard Chess position.

Error when parsing an invalid color name.

Error when parsing an invalid square name.

A piece with Color and Role.

Error when trying to play an illegal move.

Error when trying to create a Position from an illegal Setup.

Reasons for a Setup not being a legal Position.

The number of checks the respective side needs to give in order to win (in a game of Three-Check).

A not necessarily legal position.


Standard or Chess960.

KingSide (O-O) or QueenSide (O-O-O).

White or Black.

When to include the en passant square.

A file of the chessboard.

Information about a move.

Outcome of a game.

Error when parsing the outcome of a game.

A rank of the chessboard.

Piece types: Pawn, Knight, Bishop, Rook, Queen, King.

A square of the chessboard.


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.


Counts legal move paths of a given length.

Type Definitions

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