#chess #lichess

shakmaty

Chess and chess variant rules and operations

68 releases

Uses new Rust 2021

0.22.0 Sep 18, 2022
0.21.3 Jul 31, 2022
0.21.1 Mar 31, 2022
0.20.3 Dec 12, 2021
0.0.1 Mar 13, 2017

#38 in Game dev

Download history 1081/week @ 2022-08-09 990/week @ 2022-08-16 891/week @ 2022-08-23 620/week @ 2022-08-30 714/week @ 2022-09-06 786/week @ 2022-09-13 444/week @ 2022-09-20 584/week @ 2022-09-27 735/week @ 2022-10-04 366/week @ 2022-10-11 499/week @ 2022-10-18 512/week @ 2022-10-25 487/week @ 2022-11-01 921/week @ 2022-11-08 716/week @ 2022-11-15 679/week @ 2022-11-22

2,880 downloads per month
Used in 18 crates (16 directly)

GPL-3.0+

500KB
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 FEN, SAN and UCI notation.

  • 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