57 releases

Uses new Rust 2021

0.20.2 Oct 23, 2021
0.19.0 Apr 15, 2021
0.18.0 Feb 23, 2021
0.17.1 Dec 27, 2020
0.0.1 Mar 13, 2017

#39 in Parser implementations

Download history 448/week @ 2021-08-11 416/week @ 2021-08-18 165/week @ 2021-08-25 368/week @ 2021-09-01 284/week @ 2021-09-08 159/week @ 2021-09-15 68/week @ 2021-09-22 134/week @ 2021-09-29 149/week @ 2021-10-06 307/week @ 2021-10-13 326/week @ 2021-10-20 213/week @ 2021-10-27 259/week @ 2021-11-03 88/week @ 2021-11-10 123/week @ 2021-11-17 151/week @ 2021-11-24

650 downloads per month
Used in 14 crates (12 directly)

GPL-3.0+

495KB
9K SLoC

shakmaty

A Rust library for chess move generation

crates.io docs.rs

Features

  • Generate legal moves:

    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: pos.is_checkmate(), pos.is_stalemate(), pos.is_insufficient_material(), pos.outcome().

  • Read and write FENs, SANs and UCIs.

  • Supports all Lichess variants: Standard chess, Chess960, Antichess, Atomic, King of the Hill, Three-Check, Crazyhouse, Racing Kings and Horde. Provides vocabulary to implement other variants.

  • Bitboards and compact fixed shift magic attack tables.

  • Zobrist hash positions.

  • Probe Syzygy tablebases with shakmaty-syzygy.

Documentation

Read the documentation

Benchmarks

Simple perft of the initial position. No hashtables. i7-6850K CPU @ 3.60GHz.

perft 4 5
shakmaty 0.16.0 1.0 ms 24.1 ms
jordanbray/chess 3.1.1 0.8 ms 18.6 ms
Stockfish 8 (x86-64-bmi2) 4 ms 33 ms

It should be noted that Stockfish is not optimized for perft speed and also maintains additional data structures for evaluation. Newer versions of Stockfish put even less emphasis on this.

License

Shakmaty is licensed under the GPL-3.0 (or any later version at your option). See the COPYING file for the full license text.

Dependencies