### Command Line Tool Example Source: https://github.com/niklasf/shakmaty/blob/main/shakmaty-syzygy/README.md An example of using the shakmaty-syzygy command-line tool, similar to Fathom, to analyze a chess position provided in FEN format. The output shows the game annotation including the DTZ value. ```bash $ cargo run --example fathom -- --path tables/chess -- "3qk3/8/8/8/8/8/8/4K3 w - - 0 1" [Event "KvKQ"] [Site ""] [Date ""] [Round "-"] [White "Syzygy"] [Black "Syzygy"] [Result "0-1"] [FEN "3qk3/8/8/8/8/8/8/4K3 w - - 0 1"] [Annotator "shakmaty-syzygy"] [DTZ "-16 or -17"] { KvKQ with DTZ -16 or -17 } 1. Ke2 Kd7 2. Kd1 Ke6+ 3. Kc1 Qd3 4. Kb2 Qd2+ 5. Ka1 Kd5 6. Kb1 Kc4 7. Ka1 Kb3 8. Kb1 Qd1# { Checkmate } 0-1 ``` -------------------------------- ### Move Counting Visitor Example Source: https://github.com/niklasf/shakmaty/blob/main/pgn-reader/README.md Demonstrates how to implement a custom Visitor to count the number of valid moves in the main line of each chess game. This example shows the basic structure for processing PGN data with pgn-reader. ```rust use std::{io, ops::ControlFlow}; use pgn_reader::{Visitor, Reader, SanPlus}; struct MoveCounter; impl Visitor for MoveCounter { type Tags = (); type Movetext = usize; type Output = usize; fn begin_tags(&mut self) -> ControlFlow { ControlFlow::Continue(()) } fn begin_movetext(&mut self, _tags: Self::Tags) -> ControlFlow { ControlFlow::Continue(0) } fn san(&mut self, movetext: &mut Self::Movetext, _san_plus: SanPlus) -> ControlFlow { *movetext += 1; ControlFlow::Continue(()) } fn end_game(&mut self, movetext: Self::Movetext) -> Self::Output { movetext } } fn main() -> io::Result<()> { let pgn = b"1. e4 e5 2. Nf3 (2. f4) { game paused due to bad weather } 2... Nf6 *"; let mut reader = Reader::new(io::Cursor::new(&pgn)); let moves = reader.read_game(&mut MoveCounter)?; assert_eq!(moves, Some(4)); Ok(()) } ``` -------------------------------- ### Generate Legal Moves in Chess Source: https://github.com/niklasf/shakmaty/blob/main/shakmaty/README.md Use the `legal_moves` method on a `Chess` position to get all legal moves. This is useful for implementing chess engines or analysis tools. ```rust use shakmaty::{Chess, Position}; let pos = Chess::default(); let legals = pos.legal_moves(); assert_eq!(legals.len(), 20); ``` -------------------------------- ### Probe Syzygy Endgame Tablebases in Rust Source: https://github.com/niklasf/shakmaty/blob/main/shakmaty-syzygy/README.md Demonstrates how to load Syzygy tablebases from a directory and probe a given chess position for its WDL and DTZ values. Ensure tablebases are downloaded and accessible at the specified path. ```rust use shakmaty::{CastlingMode, Chess, fen::Fen}; use shakmaty_syzygy::{Tablebase, MaybeRounded, Wdl, Dtz, Syzygy}; let mut tables = Tablebase::new(); tables.add_directory("tables/chess")?; let pos: Chess = "8/8/8/8/B7/N7/K2k4/8 b - - 0 1" .parse::()? .into_position(CastlingMode::Standard)?; let wdl = tables.probe_wdl_after_zeroing(&pos)?; assert_eq!(wdl, Wdl::Loss); let dtz = tables.probe_dtz(&pos)?; assert!(matches!(dtz, MaybeRounded::Rounded(Dtz(-59)))); ``` -------------------------------- ### Play a Move in Chess Source: https://github.com/niklasf/shakmaty/blob/main/shakmaty/README.md Use the `play` method to apply a move to a chess position. This method returns a `Result` which can be used to handle invalid moves or game state changes. ```rust 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, })?; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.