pub struct Position { /* private fields */ }Expand description
A shogi position with fast do/undo and an incrementally maintained Zobrist key.
The board state is stored redundantly (mailbox + bitboards); moves are
assumed to be legal (generate them with Position::legal_moves).
A side may have no king (as in tsume-shogi problems).
A Position is a plain value: it owns nothing on the heap, so cloning it
copies and does not allocate.
Implementations§
Source§impl Position
impl Position
Sourcepub fn generate_moves(
&self,
listener: impl FnMut(MoveSet) -> ControlFlow<()>,
) -> ControlFlow<()>
pub fn generate_moves( &self, listener: impl FnMut(MoveSet) -> ControlFlow<()>, ) -> ControlFlow<()>
Calls listener with every group of legal moves for the side to
move, including pawn-drop-mate exclusion.
Returning ControlFlow::Break from listener stops generation
early — useful to answer “is there any legal move?” without building
the rest — and is reported back as the return value, so the caller
can tell a full walk from an interrupted one. No empty MoveSet
is ever passed.
The opponent’s king square is never a destination: in illegal
positions where that king could already be captured (unreachable
through legal play, but constructible via Position::new), no
king-capture move is generated — the rest of the result is
unspecified there, but this function does not panic.
Sourcepub fn legal_moves(&self) -> Vec<Move>
pub fn legal_moves(&self) -> Vec<Move>
All legal moves for the side to move.
The compatibility wrapper over Position::generate_moves; prefer
the callback form in hot code, which allocates nothing.
Sourcepub fn has_legal_moves(&self) -> bool
pub fn has_legal_moves(&self) -> bool
Whether the side to move has at least one legal move.
Stops at the first group found, so it is far cheaper than
!legal_moves().is_empty().
Source§impl Position
impl Position
Sourcepub fn new(partial: PartialPosition) -> Self
pub fn new(partial: PartialPosition) -> Self
Builds a Position from a PartialPosition.
Sourcepub fn side_to_move(&self) -> Color
pub fn side_to_move(&self) -> Color
The player to move.
Sourcepub fn king_square(&self, color: Color) -> Option<Square>
pub fn king_square(&self, color: Color) -> Option<Square>
The square of color’s king, if it is on the board.
Sourcepub fn piece_kind_bb(&self, piece_kind: PieceKind) -> Bitboard ⓘ
pub fn piece_kind_bb(&self, piece_kind: PieceKind) -> Bitboard ⓘ
The squares occupied by pieces of piece_kind, either color.