Struct shogi_core::PartialPosition
source · [−]#[repr(C)]pub struct PartialPosition { /* private fields */ }Expand description
A position with its move sequence omitted.
This data is insufficient for complete legality checking (such as repetition checking),
but in most cases it suffices. If you need a complete legality checking, use Position.
TODO: describe exactly when a position is considered valid
Implementations
sourceimpl PartialPosition
impl PartialPosition
source#[no_mangle]pub extern "C" fn PartialPosition_startpos(
buf: &mut MaybeUninit<Self>
)
#[no_mangle]pub extern "C" fn PartialPosition_startpos(
buf: &mut MaybeUninit<Self>
)
C interface of startpos.
source#[export_name = "PartialPosition_side_to_move"]pub extern "C" fn side_to_move(&self) -> Color
#[export_name = "PartialPosition_side_to_move"]pub extern "C" fn side_to_move(&self) -> Color
Finds which player is to move.
Examples:
let mut pos = PartialPosition::startpos();
assert_eq!(pos.side_to_move(), Color::Black);
pos.make_move(Move::Normal { from: Square::SQ_7G, to: Square::SQ_7F, promote: false }).unwrap();
assert_eq!(pos.side_to_move(), Color::White);sourcepub fn side_to_move_set(&mut self, side: Color)
pub fn side_to_move_set(&mut self, side: Color)
Sets which player is to move.
source#[export_name = "PartialPosition_hand_of_a_player"]pub extern "C" fn hand_of_a_player(&self, color: Color) -> Hand
#[export_name = "PartialPosition_hand_of_a_player"]pub extern "C" fn hand_of_a_player(&self, color: Color) -> Hand
Returns the Hand of a player.
sourcepub fn hand_of_a_player_mut(&mut self, color: Color) -> &mut Hand
pub fn hand_of_a_player_mut(&mut self, color: Color) -> &mut Hand
Gives the reference to the hand of the specified player.
This function makes no guarantee about the consistency of the position. Users should have a good reason when using it. Exported for parsers.
sourcepub fn hand(&self, piece: Piece) -> Option<u8>
pub fn hand(&self, piece: Piece) -> Option<u8>
Returns how many pieces of piece are in hand.
If piece is not a valid piece in hand, this method returns None.
source#[export_name = "PartialPosition_ply"]pub extern "C" fn ply(&self) -> u16
#[export_name = "PartialPosition_ply"]pub extern "C" fn ply(&self) -> u16
Finds how many moves were made.
sourcepub fn ply_set(&mut self, ply: u16) -> bool
pub fn ply_set(&mut self, ply: u16) -> bool
Sets how many moves are made. Returns whether this operation was successful.
This operation succeeds iff ply != 0.
source#[no_mangle]pub extern "C" fn PartialPosition_piece_at(
&self,
square: Square
) -> OptionPiece
#[no_mangle]pub extern "C" fn PartialPosition_piece_at(
&self,
square: Square
) -> OptionPiece
C interface to PartialPosition::piece_at.
sourcepub fn piece_set(&mut self, square: Square, piece: Option<Piece>)
pub fn piece_set(&mut self, square: Square, piece: Option<Piece>)
Place a piece on a square.
This function makes no guarantee about the consistency of the position. Users should have a good reason when using it. Exported for parsers.
source#[export_name = "PartialPosition_occupied_bitboard"]pub extern "C" fn occupied_bitboard(&self) -> BitboardⓘNotable traits for Bitboardimpl Iterator for Bitboard type Item = Square;
#[export_name = "PartialPosition_occupied_bitboard"]pub extern "C" fn occupied_bitboard(&self) -> BitboardⓘNotable traits for Bitboardimpl Iterator for Bitboard type Item = Square;
Finds the subset of squares with a piece.
Since: 0.1.4
source#[export_name = "PartialPosition_vacant_bitboard"]pub extern "C" fn vacant_bitboard(&self) -> BitboardⓘNotable traits for Bitboardimpl Iterator for Bitboard type Item = Square;
#[export_name = "PartialPosition_vacant_bitboard"]pub extern "C" fn vacant_bitboard(&self) -> BitboardⓘNotable traits for Bitboardimpl Iterator for Bitboard type Item = Square;
Finds the subset of squares with no pieces.
source#[export_name = "PartialPosition_player_bitboard"]pub extern "C" fn player_bitboard(&self, color: Color) -> BitboardⓘNotable traits for Bitboardimpl Iterator for Bitboard type Item = Square;
#[export_name = "PartialPosition_player_bitboard"]pub extern "C" fn player_bitboard(&self, color: Color) -> BitboardⓘNotable traits for Bitboardimpl Iterator for Bitboard type Item = Square;
Finds the subset of squares where a piece of the specified player is placed.
source#[export_name = "PartialPosition_piece_bitboard"]pub extern "C" fn piece_bitboard(&self, piece: Piece) -> BitboardⓘNotable traits for Bitboardimpl Iterator for Bitboard type Item = Square;
#[export_name = "PartialPosition_piece_bitboard"]pub extern "C" fn piece_bitboard(&self, piece: Piece) -> BitboardⓘNotable traits for Bitboardimpl Iterator for Bitboard type Item = Square;
Finds the subset of squares where a piece is placed.
Examples:
let pos = PartialPosition::startpos();
let black_rook = pos.piece_bitboard(Piece::B_R);
assert_eq!(black_rook, Bitboard::single(Square::SQ_2H));
let white_rook = pos.piece_bitboard(Piece::W_R);
assert_eq!(white_rook, Bitboard::single(Square::SQ_8B));source#[export_name = "PartialPosition_piece_kind_bitboard"]pub extern "C" fn piece_kind_bitboard(
&self,
piece_kind: PieceKind
) -> BitboardⓘNotable traits for Bitboardimpl Iterator for Bitboard type Item = Square;
#[export_name = "PartialPosition_piece_kind_bitboard"]pub extern "C" fn piece_kind_bitboard(
&self,
piece_kind: PieceKind
) -> BitboardⓘNotable traits for Bitboardimpl Iterator for Bitboard type Item = Square;
Finds the subset of squares where a PieceKind is placed.
Examples:
let pos = PartialPosition::startpos();
let rooks = pos.piece_kind_bitboard(PieceKind::Rook);
assert_eq!(rooks, Bitboard::single(Square::SQ_2H) | Bitboard::single(Square::SQ_8B));sourcepub fn last_move(&self) -> Option<Move>
pub fn last_move(&self) -> Option<Move>
Returns the last move, if it exists.
Examples:
use shogi_core::PartialPosition;
assert_eq!(PartialPosition::startpos().last_move(), None);sourcepub fn last_compact_move(&self) -> Option<CompactMove>
pub fn last_compact_move(&self) -> Option<CompactMove>
Returns the last move, if it exists.
Examples:
use shogi_core::PartialPosition;
assert_eq!(PartialPosition::startpos().last_compact_move(), None);source#[no_mangle]pub extern "C" fn PartialPosition_last_compact_move(
&self
) -> OptionCompactMove
#[no_mangle]pub extern "C" fn PartialPosition_last_compact_move(
&self
) -> OptionCompactMove
C interface to PartialPosition::last_compact_move.
pub fn king_position(&self, color: Color) -> Option<Square>
sourcepub fn make_move(&mut self, mv: Move) -> Option<()>
pub fn make_move(&mut self, mv: Move) -> Option<()>
Makes a move. Note that this function will never check legality.
Returns Some(()) if the given move makes sense, i.e., moves a piece to another square or drops a piece on a vacant square.
If it returns None, it is guaranteed that self is not modified.
source#[export_name = "PartialPosition_make_compact_move"]pub extern "C" fn make_compact_move(&mut self, mv: CompactMove) -> bool
#[export_name = "PartialPosition_make_compact_move"]pub extern "C" fn make_compact_move(&mut self, mv: CompactMove) -> bool
Makes a move. This function is a C-compatible counterpart of make_move.
Note that this function will never check legality.
Returns true if the given move makes sense, i.e., moves a piece to another square or drops a piece on a vacant square.
If it returns false, it is guaranteed that self is not modified.
sourcepub fn to_sfen<W: Write>(&self, sink: &mut W) -> FmtResult
pub fn to_sfen<W: Write>(&self, sink: &mut W) -> FmtResult
Write the current position in SFEN notation.
sourcepub fn to_sfen_owned(&self) -> String
Available on crate feature alloc only.
pub fn to_sfen_owned(&self) -> String
alloc only.Returns the SFEN representation of the current position.
Examples:
let pos = PartialPosition::startpos();
let s = pos.to_sfen_owned();
assert_eq!(
s,
"lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL b - 1",
);Trait Implementations
sourceimpl Clone for PartialPosition
impl Clone for PartialPosition
sourcefn clone(&self) -> PartialPosition
fn clone(&self) -> PartialPosition
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source. Read more
sourceimpl Debug for PartialPosition
impl Debug for PartialPosition
sourceimpl Default for PartialPosition
impl Default for PartialPosition
sourceimpl Hash for PartialPosition
Available on crate feature hash only.
impl Hash for PartialPosition
hash only.sourceimpl Ord for PartialPosition
Available on crate feature ord only.
impl Ord for PartialPosition
ord only.1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl PartialEq<PartialPosition> for PartialPosition
impl PartialEq<PartialPosition> for PartialPosition
sourcefn eq(&self, other: &PartialPosition) -> bool
fn eq(&self, other: &PartialPosition) -> bool
This method tests for self and other values to be equal, and is used
by ==. Read more
sourcefn ne(&self, other: &PartialPosition) -> bool
fn ne(&self, other: &PartialPosition) -> bool
This method tests for !=.
sourceimpl PartialOrd<PartialPosition> for PartialPosition
Available on crate feature ord only.
impl PartialOrd<PartialPosition> for PartialPosition
ord only.sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
This method returns an ordering between self and other values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
impl Eq for PartialPosition
impl StructuralEq for PartialPosition
impl StructuralPartialEq for PartialPosition
Auto Trait Implementations
impl RefUnwindSafe for PartialPosition
impl Send for PartialPosition
impl Sync for PartialPosition
impl Unpin for PartialPosition
impl UnwindSafe for PartialPosition
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more