pub struct Generator { /* private fields */ }Expand description
Chess moves generator. Can generate attacks (BitBoard) and Moves for all Chess pieces. Queen does not have it’s own generator, rather is considered both Rook and Bishop.
§Examples
§Generate all legal moves for a board
use chessgen::{ChessBoard, Generator, Move};
let mut board = ChessBoard::from_string("
a b c d e f g h
8 r n b q k b n r 8
7 p p p p p p p p 7
6 - - - - - - - - 6
5 - - - - - - - - 5
4 - - - - - - - - 4
3 - - - - - - - - 3
2 P P P P P P P P 2
1 R N B Q K B N R 1
a b c d e f g h
").unwrap();
let moves = board.legal_moves();
assert_eq!(moves.len(), 20);
board = board.validate_and_apply_move(&Move::from_string("b1c3").unwrap()).unwrap();
assert_eq!(
board.pieces,
ChessBoard::from_string("
a b c d e f g h
8 r n b q k b n r 8
7 p p p p p p p p 7
6 - - - - - - - - 6
5 - - - - - - - - 5
4 - - - - - - - - 4
3 - - N - - - - - 3
2 P P P P P P P P 2
1 R - B Q K B N R 1
a b c d e f g h
").unwrap().pieces
);
assert!(board.validate_and_apply_move(&Move::from_string("a1a8").unwrap()).is_err());Implementations§
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Generator
impl RefUnwindSafe for Generator
impl Send for Generator
impl Sync for Generator
impl Unpin for Generator
impl UnwindSafe for Generator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more