Skip to main content

Setup

Struct Setup 

Source
pub struct Setup { /* private fields */ }
Expand description

A builder type for chess positions.

This type is useful to edit a position without having to ensure it stays legal at every step. It must be validated and converted to a Position using Setup::into_position before generating moves.

§Text description

Forsyth-Edwards Notation (FEN) is typically used to describe chess positions as text. eschac uses a slightly different notation, which simply removes the last two fields of the FEN record (i.e. the halfmove clock and the fullmove number) as the Position type does not keep track of those. For example, the starting position is recorded as rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq -.

Display and FromStr are purposely not implemented on Setup as there does not exist a truely canonical format for writing chess positions. The format described above is implemented in from_text_record and to_text_record.

Implementations§

Source§

impl Setup

Source

pub fn new() -> Self

Creates an empty board, i.e. 8/8/8/8/8/8/8/8 w - -.

Source

pub fn from_text_record(record: &str) -> Result<Self, ParseRecordError>

Reads a position from a text record (see from_ascii_record).

Source

pub fn from_ascii_record(record: &[u8]) -> Result<Self, ParseRecordError>

Reads a position from a text record.

Source

pub fn set(&self, square: Square, piece: Option<Piece>) -> Self

Sets the occupancy of a square.

Source

pub fn set_turn(&self, color: Color) -> Self

Sets the color to play.

Source

pub fn switch_turn(&self) -> Self

Switches the color to play.

Source

pub fn set_castling_rights( &self, color: Color, castle: Castle, value: bool, ) -> Self

Sets the castling rights for the given color and side.

Source

pub fn set_en_passant_target_square(&self, square: Option<Square>) -> Self

Sets the en passant target square.

Source

pub fn mirror(&self) -> Self

Returns the mirror image of the position.

The mirror of a position is the position obtained after reflecting the placement of pieces horizontally, inverting the color of all the pieces, inverting the turn, and reflecting the castling rights as well as the en passant target square.

For example, the mirror image of rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b Kq e3 is rnbqkbnr/pppp1ppp/8/4p3/8/8/PPPPPPPP/RNBQKBNR w Qk e6.

Source

pub fn illegal_reasons(&self) -> IllegalPositionReasons ⓘ

Checks for the validity of the position, returning a set of potential reasons.

Source

pub fn into_position(self) -> Result<Position, IllegalPosition>

Tries to convert the position into the Position type.

Some unreachable positions are rejected, see IllegalPositionReason for details.

Source

pub unsafe fn into_position_unchecked(self) -> Position

Converts the position into the Position type without checking if it is valid.

Safety: if the position is not valid, using it might cause undefined behavior.

Source

pub fn from_bitboards(bitboards: [Bitboard; 5]) -> Option<Self>

Returns the position encoded by the given bitboards, or None if the bitboards are not compatible with the format described in AsSetup::bitboards.

Source

pub unsafe fn from_bitboards_unchecked(bitboards: [Bitboard; 5]) -> Self

Returns the position encoded by the given bitboards, without checking if the format is respected.

Safety: if the bitboards are ill-formed, then using the position obtained from this method might cause undefined behavior.

Trait Implementations§

Source§

impl AsSetup for Setup

Source§

fn as_setup(&self) -> &Setup

Source§

fn bitboards(&self) -> [Bitboard; 5]

Returns the inner bitboard representation of the position. Read more
Source§

fn get(&self, square: Square) -> Option<Piece>

Returns the piece on the square, if any.
Source§

fn turn(&self) -> Color

Returns the color to play.
Source§

fn castling_rights(&self, color: Color, castle: Castle) -> bool

Returns true if castling is available for the given color and side.
Source§

fn en_passant_target_square(&self) -> Option<Square>

Returns the optional en passant target square.
Source§

fn pieces(&self) -> ByColor<ByRole<Bitboard>>

Returns the squares occupied by each type & color of piece.
Source§

fn to_text_record(&self) -> String

Returns the text record of the position (see write_text_record).
Source§

fn write_text_record<W: Write>(&self, w: &mut W) -> Result

Writes the text record of the position.
Source§

impl Clone for Setup

Source§

fn clone(&self) -> Setup

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 Debug for Setup

Source§

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

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

impl Default for Setup

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for Setup

Source§

impl Ord for Setup

Source§

fn cmp(&self, other: &Setup) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Setup

Source§

fn eq(&self, other: &Setup) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Setup

Source§

fn partial_cmp(&self, other: &Setup) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for Setup

Auto Trait Implementations§

§

impl Freeze for Setup

§

impl RefUnwindSafe for Setup

§

impl Send for Setup

§

impl Sync for Setup

§

impl Unpin for Setup

§

impl UnsafeUnpin for Setup

§

impl UnwindSafe for Setup

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 = 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.