[][src]Struct chess::MoveGen

pub struct MoveGen { /* fields omitted */ }

An incremental move generator

This structure enumerates moves slightly slower than board.enumerate_moves(...), but has some extra features, such as:

Examples

use chess::MoveGen;
use chess::Board;
use chess::EMPTY;
use chess::construct;

// create a board with the initial position
let board = Board::default();

// create an iterable
let mut iterable = MoveGen::new_legal(&board);

// make sure .len() works.
assert_eq!(iterable.len(), 20); // the .len() function does *not* consume the iterator

// lets iterate over targets.
let targets = board.color_combined(!board.side_to_move());
iterable.set_iterator_mask(*targets);

// count the number of targets
let mut count = 0;
for _ in &mut iterable {
    count += 1;
    // This move captures one of my opponents pieces (with the exception of en passant)
}

// now, iterate over the rest of the moves
iterable.set_iterator_mask(!EMPTY);
for _ in &mut iterable {
    count += 1;
    // This move does not capture anything
}

// make sure it works
assert_eq!(count, 20);

Methods

impl MoveGen[src]

Create a new MoveGen structure, only generating legal moves

pub fn remove_mask(&mut self, mask: BitBoard)[src]

Never, ever, iterate any moves that land on the following squares

pub fn remove_move(&mut self, chess_move: ChessMove) -> bool[src]

Never, ever, iterate this move

pub fn set_iterator_mask(&mut self, mask: BitBoard)[src]

For now, Only iterate moves that land on the following squares Note: Once iteration is completed, you can pass in a mask of ! EMPTY to get the remaining moves, or another mask

pub fn legal_quick(board: &Board, chess_move: ChessMove) -> bool[src]

This function checks the legality only for moves generated by MoveGen.

Calling this function for moves not generated by MoveGen will result in possibly incorrect results, and making that move on the Board will result in undefined behavior. This function may panic! if these rules are not followed.

If you are validating a move from a user, you should call the .legal() function.

pub fn movegen_perft_test(board: &Board, depth: usize) -> usize[src]

Fastest perft test with this structure

Trait Implementations

impl ExactSizeIterator for MoveGen[src]

fn len(&self) -> usize[src]

Give the exact length of this iterator

impl Iterator for MoveGen[src]

type Item = ChessMove

The type of the elements being iterated over.

fn size_hint(&self) -> (usize, Option<usize>)[src]

Give a size_hint to some functions that need it

fn next(&mut self) -> Option<ChessMove>[src]

Find the next chess move.

Auto Trait Implementations

impl RefUnwindSafe for MoveGen

impl Send for MoveGen

impl Sync for MoveGen

impl Unpin for MoveGen

impl UnwindSafe for MoveGen

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.