Generator

Struct Generator 

Source
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

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§

Source§

impl Debug for Generator

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.