Trait shakmaty::Position
[−]
[src]
pub trait Position: Setup + Default + Clone { const TRACK_PROMOTED: bool; const KING_PROMOTIONS: bool; fn from_setup<S: Setup>(setup: &S) -> Result<Self, PositionError>; fn legal_moves(&self, moves: &mut MoveList); fn is_variant_end(&self) -> bool; fn is_insufficient_material(&self) -> bool; fn variant_outcome(&self) -> Option<Outcome>; fn play_unchecked(self, m: &Move) -> Self; fn king_attackers(&self, square: Square, attacker: Color) -> Bitboard { ... } fn checkers(&self) -> Bitboard { ... } fn is_legal(&self, m: &Move) -> bool { ... } fn is_zeroing(&self, m: &Move) -> bool { ... } fn is_checkmate(&self) -> bool { ... } fn is_stalemate(&self) -> bool { ... } fn is_game_over(&self) -> bool { ... } fn outcome(&self) -> Option<Outcome> { ... } fn play(self, m: &Move) -> Result<Self, ()> { ... } }
A legal chess or chess variant position. See Chess
and
shakmaty::variants
for concrete implementations.
Associated Constants
const TRACK_PROMOTED: bool
TRACK_PROMOTED: bool
Whether or not promoted pieces are special in the respective chess
variant. For example in Crazyhouse a promoted queen should be marked
as Q~
in FENs and will become a pawn when captured.
const KING_PROMOTIONS: bool
KING_PROMOTIONS: bool
Wether pawns can be promoted to kings in this variant.
Required Methods
fn from_setup<S: Setup>(setup: &S) -> Result<Self, PositionError>
Validates a Setup
and constructs a position.
fn legal_moves(&self, moves: &mut MoveList)
Generates legal moves.
fn is_variant_end(&self) -> bool
Checks if the game is over due to a special variant end condition.
Note that for example stalemate is not considered a variant-specific
end condition (is_variant_end()
will return false
), but it can have
a special variant_outcome()
in suicide chess.
fn is_insufficient_material(&self) -> bool
Tests for insufficient winning material.
fn variant_outcome(&self) -> Option<Outcome>
Tests special variant winning, losing and drawing conditions.
fn play_unchecked(self, m: &Move) -> Self
Plays a move. It is the callers responsibility to ensure the move is legal.
Panics
Illegal moves can corrupt the state of the position and may (or may not) panic or cause panics on future calls.
Provided Methods
fn king_attackers(&self, square: Square, attacker: Color) -> Bitboard
Attacks that a king on square
would have to deal with.
fn checkers(&self) -> Bitboard
Bitboard of pieces giving check.
fn is_legal(&self, m: &Move) -> bool
Tests a move for legality.
fn is_zeroing(&self, m: &Move) -> bool
Tests if a move zeros the halfmove clock.
fn is_checkmate(&self) -> bool
Tests for checkmate.
fn is_stalemate(&self) -> bool
Tests for stalemate.
fn is_game_over(&self) -> bool
Tests if the game is over due to checkmate, stalemate, insufficient material or variant end.
fn outcome(&self) -> Option<Outcome>
The outcome of the game, or None
if the game is not over.
fn play(self, m: &Move) -> Result<Self, ()>
Validates and plays a move. Accepts only legal moves and safe null moves.
Implementors
impl Position for Chess
impl Position for Crazyhouse
impl Position for KingOfTheHill
impl Position for Giveaway
impl Position for ThreeCheck
impl Position for Horde
impl Position for Atomic
impl Position for RacingKings