2 unstable releases

Uses new Rust 2024

new 0.2.0 Mar 29, 2025
0.1.0 Mar 23, 2025

#611 in Game dev

Download history 57/week @ 2025-03-17 108/week @ 2025-03-24

165 downloads per month

MIT license

145KB
3K SLoC

Schachmatt

Schachmatt is a chess library for rust.

Crates.io Crates.io License

Intention

This library can be used to run chess games, generate legal moves or create and work with standardized chess data formats.

Examples

The following example starts a game of chess and plays random moves until the game is over

use schachmatt::{Game, GameResult, PlayerColor};
use rand::seq::IndexedRandom;
use rand::rng;

/// Starts a game of chess and plays random moves until the game is over.
/// Afterwards the game result is printed.
fn main() {

    let mut game = Game::default();
    let mut rng = rng();

    while game.get_game_result().is_none() {
        let possible_moves = game.get_current_state().get_possible_moves();
        let turn_to_play = possible_moves.choose(&mut rng).unwrap();

        game.execute_turn(*turn_to_play);
    }

    let game_result = match game.get_game_result().unwrap() {
        GameResult::Draw => "Draw",
        GameResult::Over(player_color) => match player_color {
            PlayerColor::Black => "Black won",
            PlayerColor::White => "White won",
        }
    };

    println!("{}", game_result);
}

See more examples:

Data format support

Schachmatt can import and export chess games, position and moves in the following formats:

  • Forsyth-Edwards Notation (FEN)
  • Long algebraic notation (LAN)
  • Standard algebraic notation (SAN)
  • Portable game notation (PGN)

Dependencies

~2–2.8MB
~56K SLoC