Skip to main content

Moves

Struct Moves 

Source
pub struct Moves<'l> { /* private fields */ }
Expand description

The list of all the legal moves on a position. It is returned by Position::legal_moves.

This type lies on the stack and has a fixed capacity of 218 moves, as there exists no reachable position with more legal moves1.


  1. In 1964, Nenad Petrović published a composition with 218 legal moves. 60 years later, this was proven to be optimal by Tobs40. Even though the Position type can represent some unreachable positions the proof still holds, as its definition of a position is even less restrictive. ↩

Implementations§

Source§

impl<'l> Moves<'l>

Source

pub fn position(&self) -> &'l Position

Returns the position on which the moves are played.

Source

pub fn iter(&'l self) -> MovesIter<'l> ⓘ

Iterates over the moves.

Source

pub fn len(&self) -> usize

Returns the number of moves in the list.

Source

pub fn is_empty(&self) -> bool

Returns true if there is no legal move on the position.

Source

pub fn is_check(&self) -> bool

Returns true if the king is in check.

Returns true if taking en passant is legal on the position.

Source

pub fn get(&self, index: usize) -> Option<Move<'l>>

Returns the move at the given index, if it exists.

Source

pub fn sort(&mut self)

Sorts the list in ascending order.

Source

pub fn sort_by<F>(&mut self, compare: F)
where F: for<'a> FnMut(Move<'a>, Move<'a>) -> Ordering,

Available on crate feature alloc only.

Sorts the list in ascending order with a comparison function, preserving initial order of equal elements.

See slice::sort_by for details.

Source

pub fn sort_unstable_by<F>(&mut self, compare: F)
where F: for<'a> FnMut(Move<'a>, Move<'a>) -> Ordering,

Sorts the list in ascending order with a comparison function, without preserving the initial order of equal elements.

See slice::sort_unstable_by for details.

Source

pub fn select_nth_unstable(&mut self, index: usize) -> Move<'l>

Reorders the slice such that the element at index is at a sort-order position.

See slice::select_nth_unstable for details.

Source

pub fn select_nth_unstable_by<F>( &mut self, index: usize, compare: F, ) -> Move<'l>
where F: for<'a> FnMut(Move<'a>, Move<'a>) -> Ordering,

Reorders the slice with a comparator function such that the element at index is at a sort-order position.

See slice::select_nth_unstable_by for details.

Trait Implementations§

Source§

impl<'l> Clone for Moves<'l>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'l> Debug for Moves<'l>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'l> IntoIterator for &'l Moves<'l>

Source§

type Item = Move<'l>

The type of the elements being iterated over.
Source§

type IntoIter = MovesIter<'l>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'l> IntoIterator for Moves<'l>

Source§

type Item = Move<'l>

The type of the elements being iterated over.
Source§

type IntoIter = MovesIntoIter<'l>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<'l> Freeze for Moves<'l>

§

impl<'l> RefUnwindSafe for Moves<'l>

§

impl<'l> Send for Moves<'l>

§

impl<'l> Sync for Moves<'l>

§

impl<'l> Unpin for Moves<'l>

§

impl<'l> UnsafeUnpin for Moves<'l>

§

impl<'l> UnwindSafe for Moves<'l>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.