pub trait Position {
Show 39 methods
// Required methods
fn board(&self) -> &Board;
fn promoted(&self) -> Bitboard;
fn pockets(&self) -> Option<&ByColor<ByRole<u8>>>;
fn turn(&self) -> Color;
fn castles(&self) -> &Castles;
fn maybe_ep_square(&self) -> Option<Square>;
fn remaining_checks(&self) -> Option<&ByColor<RemainingChecks>>;
fn halfmoves(&self) -> u32;
fn fullmoves(&self) -> NonZeroU32;
fn into_setup(self, mode: EnPassantMode) -> Setup;
fn legal_moves(&self) -> MoveList;
fn is_variant_end(&self) -> bool;
fn has_insufficient_material(&self, color: Color) -> bool;
fn variant_outcome(&self) -> Option<Outcome>;
fn play_unchecked(&mut self, m: &Move);
// Provided methods
fn san_candidates(&self, role: Role, to: Square) -> MoveList { ... }
fn castling_moves(&self, side: CastlingSide) -> MoveList { ... }
fn en_passant_moves(&self) -> MoveList { ... }
fn capture_moves(&self) -> MoveList { ... }
fn promotion_moves(&self) -> MoveList { ... }
fn is_irreversible(&self, m: &Move) -> bool { ... }
fn king_attackers(
&self,
square: Square,
attacker: Color,
occupied: Bitboard
) -> Bitboard { ... }
fn us(&self) -> Bitboard { ... }
fn our(&self, role: Role) -> Bitboard { ... }
fn them(&self) -> Bitboard { ... }
fn their(&self, role: Role) -> Bitboard { ... }
fn is_legal(&self, m: &Move) -> bool { ... }
fn pseudo_legal_ep_square(&self) -> Option<Square> { ... }
fn legal_ep_square(&self) -> Option<Square> { ... }
fn ep_square(&self, mode: EnPassantMode) -> Option<Square> { ... }
fn checkers(&self) -> Bitboard { ... }
fn is_check(&self) -> bool { ... }
fn is_checkmate(&self) -> bool { ... }
fn is_stalemate(&self) -> bool { ... }
fn is_insufficient_material(&self) -> bool { ... }
fn is_game_over(&self) -> bool { ... }
fn outcome(&self) -> Option<Outcome> { ... }
fn play(self, m: &Move) -> Result<Self, PlayError<Self>>
where Self: Sized { ... }
fn swap_turn(self) -> Result<Self, PositionError<Self>>
where Self: Sized + FromSetup { ... }
}
Expand description
A playable chess or chess variant position. See Chess
for a concrete
implementation.
§Equality
All provided variants implement Hash
,
PartialEq
, and Eq
according
to FIDE rules for repeated positions. That is, considering
- piece positions
- promoted pieces only in Crazyhouse
- pockets only in Crazyhouse
- turn
- current castling rights
- currently available legal en passant moves
- remaining checks only in Three-Check
but specifally ignoring halfmove and fullmove counters.
Use Setup
for structural equality.
Required Methods§
sourcefn maybe_ep_square(&self) -> Option<Square>
fn maybe_ep_square(&self) -> Option<Square>
Unconditionally gets the en passant target square after a double pawn push, even if no en passant capture is actually possible.
Also see Position::pseudo_legal_ep_square()
and
Position::legal_ep_square()
.
sourcefn remaining_checks(&self) -> Option<&ByColor<RemainingChecks>>
fn remaining_checks(&self) -> Option<&ByColor<RemainingChecks>>
Remaining checks in Three-Check.
sourcefn halfmoves(&self) -> u32
fn halfmoves(&self) -> u32
Number of half-moves since the last capture or pawn move.
sourcefn fullmoves(&self) -> NonZeroU32
fn fullmoves(&self) -> NonZeroU32
Move number. Starts at 1 and is increased after every black move.
sourcefn into_setup(self, mode: EnPassantMode) -> Setup
fn into_setup(self, mode: EnPassantMode) -> Setup
Converts the position to the current Setup
.
sourcefn legal_moves(&self) -> MoveList
fn legal_moves(&self) -> MoveList
Generates all legal moves.
sourcefn is_variant_end(&self) -> bool
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.
sourcefn has_insufficient_material(&self, color: Color) -> bool
fn has_insufficient_material(&self, color: Color) -> bool
Tests if a side has insufficient winning material.
Returns false
if there is any series of legal moves that allows
color
to win the game.
The converse is not necessarily true for this static check.
The position might be locked up such that color
can never win the
game (even if !color
cooperates), or insufficient material might only
become apparent after a forced sequence of moves.
The minimum guarantee is: Looking only at the material configuration,
taking into account color complexes of bishops and knights, but not
concrete piece positions, is there a position with the same material
configuration where color
can win with a series of legal moves?
If not, then color
has insufficient winning material.
For a complete dynamic unwinnability solver see https://chasolver.org/.
sourcefn variant_outcome(&self) -> Option<Outcome>
fn variant_outcome(&self) -> Option<Outcome>
Tests special variant winning, losing and drawing conditions.
sourcefn play_unchecked(&mut self, m: &Move)
fn play_unchecked(&mut self, m: &Move)
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. Consider using
Position::play()
if you cannot guarantee legality.
Provided Methods§
sourcefn san_candidates(&self, role: Role, to: Square) -> MoveList
fn san_candidates(&self, role: Role, to: Square) -> MoveList
Generates a subset of legal moves: All piece moves and drops of type
role
to the square to
, excluding castling moves.
sourcefn castling_moves(&self, side: CastlingSide) -> MoveList
fn castling_moves(&self, side: CastlingSide) -> MoveList
Generates legal castling moves.
sourcefn en_passant_moves(&self) -> MoveList
fn en_passant_moves(&self) -> MoveList
Generates en passant moves.
sourcefn capture_moves(&self) -> MoveList
fn capture_moves(&self) -> MoveList
Generates capture moves.
sourcefn promotion_moves(&self) -> MoveList
fn promotion_moves(&self) -> MoveList
Generate promotion moves.
sourcefn is_irreversible(&self, m: &Move) -> bool
fn is_irreversible(&self, m: &Move) -> bool
Tests if a move is irreversible.
In standard chess, pawn moves, captures, moves that destroy castling rights, and moves that cede en-passant are irreversible.
The implementation has false-negatives, because it does not consider forced lines. For example, a checking move that will force the king to lose castling rights is not considered irreversible, only the actual king move is.
sourcefn king_attackers(
&self,
square: Square,
attacker: Color,
occupied: Bitboard
) -> Bitboard
fn king_attackers( &self, square: Square, attacker: Color, occupied: Bitboard ) -> Bitboard
Attacks that a king on square
would have to deal with.
sourcefn our(&self, role: Role) -> Bitboard
fn our(&self, role: Role) -> Bitboard
Squares occupied with the given piece type by the side to move.
sourcefn their(&self, role: Role) -> Bitboard
fn their(&self, role: Role) -> Bitboard
Squares occupied with the given piece type by the opponent of the side to move.
sourcefn pseudo_legal_ep_square(&self) -> Option<Square>
fn pseudo_legal_ep_square(&self) -> Option<Square>
The en passant square, if it is the target of a pseudo-legal en passant move.
sourcefn legal_ep_square(&self) -> Option<Square>
fn legal_ep_square(&self) -> Option<Square>
The en passant square, if it really is the target of a legal en passant move.
sourcefn ep_square(&self, mode: EnPassantMode) -> Option<Square>
fn ep_square(&self, mode: EnPassantMode) -> Option<Square>
The en passant square.
sourcefn is_checkmate(&self) -> bool
fn is_checkmate(&self) -> bool
Tests for checkmate.
sourcefn is_stalemate(&self) -> bool
fn is_stalemate(&self) -> bool
Tests for stalemate.
sourcefn is_insufficient_material(&self) -> bool
fn is_insufficient_material(&self) -> bool
Tests if both sides have insufficient winning material.
sourcefn is_game_over(&self) -> bool
fn is_game_over(&self) -> bool
Tests if the game is over due to checkmate, stalemate, insufficient material or variant end.
sourcefn play(self, m: &Move) -> Result<Self, PlayError<Self>>where
Self: Sized,
fn play(self, m: &Move) -> Result<Self, PlayError<Self>>where
Self: Sized,
Plays a move.
§Errors
Returns a PlayError
if the move is not legal. You can use
Position::play_unchecked()
if you can guarantee legality.
sourcefn swap_turn(self) -> Result<Self, PositionError<Self>>
fn swap_turn(self) -> Result<Self, PositionError<Self>>
Swap turns. This is sometimes called “playing a null move”.
§Errors
Returns PositionError
if swapping turns is not possible (usually
due to a check that has to be averted).
Implementors§
impl Position for VariantPosition
variant
only.impl Position for Antichess
variant
only.impl Position for Atomic
variant
only.impl Position for Chess
impl Position for Crazyhouse
variant
only.impl Position for Horde
variant
only.impl Position for KingOfTheHill
variant
only.impl Position for RacingKings
variant
only.impl Position for ThreeCheck
variant
only.