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
impl Setup
Sourcepub fn from_text_record(record: &str) -> Result<Self, ParseRecordError>
pub fn from_text_record(record: &str) -> Result<Self, ParseRecordError>
Reads a position from a text record
(see from_ascii_record).
Sourcepub fn from_ascii_record(record: &[u8]) -> Result<Self, ParseRecordError>
pub fn from_ascii_record(record: &[u8]) -> Result<Self, ParseRecordError>
Reads a position from a text record.
Sourcepub fn set(&self, square: Square, piece: Option<Piece>) -> Self
pub fn set(&self, square: Square, piece: Option<Piece>) -> Self
Sets the occupancy of a square.
Sourcepub fn switch_turn(&self) -> Self
pub fn switch_turn(&self) -> Self
Switches the color to play.
Sourcepub fn set_castling_rights(
&self,
color: Color,
castle: Castle,
value: bool,
) -> Self
pub fn set_castling_rights( &self, color: Color, castle: Castle, value: bool, ) -> Self
Sets the castling rights for the given color and side.
Sourcepub fn set_en_passant_target_square(&self, square: Option<Square>) -> Self
pub fn set_en_passant_target_square(&self, square: Option<Square>) -> Self
Sets the en passant target square.
Sourcepub fn mirror(&self) -> Self
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.
Sourcepub fn illegal_reasons(&self) -> IllegalPositionReasons ⓘ
pub fn illegal_reasons(&self) -> IllegalPositionReasons ⓘ
Checks for the validity of the position, returning a set of potential reasons.
Sourcepub fn into_position(self) -> Result<Position, IllegalPosition>
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.
Sourcepub unsafe fn into_position_unchecked(self) -> Position
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.
Sourcepub fn from_bitboards(bitboards: [Bitboard; 5]) -> Option<Self>
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.
Sourcepub unsafe fn from_bitboards_unchecked(bitboards: [Bitboard; 5]) -> Self
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
impl AsSetup for Setup
fn as_setup(&self) -> &Setup
Source§fn bitboards(&self) -> [Bitboard; 5]
fn bitboards(&self) -> [Bitboard; 5]
Source§fn castling_rights(&self, color: Color, castle: Castle) -> bool
fn castling_rights(&self, color: Color, castle: Castle) -> bool
true if castling is available for the given color and side.Source§fn en_passant_target_square(&self) -> Option<Square>
fn en_passant_target_square(&self) -> Option<Square>
Source§fn pieces(&self) -> ByColor<ByRole<Bitboard>>
fn pieces(&self) -> ByColor<ByRole<Bitboard>>
Source§fn to_text_record(&self) -> String
fn to_text_record(&self) -> String
write_text_record).