A feature-rich chess library for Rust based on shakmaty.
sh
$ cargo add sacrifice
```rust let mut game = sacrifice::Game::from_pgn( "1. e4 { This blunders into the Sicilian Defense } 1... c5" ); println!("{}", game); // exports the PGN string
// Play the Open Sicilian let opensicilian = sacrifice::Move::Normal { role: sacrifice::Role::Knight, from: sacrifice::Square::G1, capture: None, to: sacrifice::Square::F3, promotion: None, }; let newnode = game.addnode(game.root(), opensicilian); println!("{}", game); // exports the PGN string after 2. Nf3
// Take back 2. Nf3 move game.removenode(newnode); println!("{}", game);
// What if someone want to play 1. d4? let queenspawn = sacrifice::Move::Normal { role: sacrifice::Role::Pawn, from: sacrifice::Square::D2, capture: None, to: sacrifice::Square::D4, promotion: None, }; let newnode = game.addnode(game.root(), queenspawn); println!("{}", game); // 1. e4 (1. d4) 1... c5
// Promote 1. d4 game.promotevariation(newnode); println!("{}", game); // 1. d4 (1. e4 c5) ```
Currently it supports