Struct shogi_core::Position
source · [−]pub struct Position { /* private fields */ }alloc only.Expand description
A position. It provides sufficient data for legality checking.
Implementations
sourceimpl Position
impl Position
source#[export_name = "Position_inner"]pub extern "C" fn inner(&self) -> &PartialPosition
#[export_name = "Position_inner"]pub extern "C" fn inner(&self) -> &PartialPosition
Returns the inner PartialPosition.
source#[export_name = "Position_initial_position"]pub extern "C" fn initial_position(&self) -> &PartialPosition
#[export_name = "Position_initial_position"]pub extern "C" fn initial_position(&self) -> &PartialPosition
Returns the initial position of Position, i.e., the position before any moves given to it.
source#[no_mangle]pub extern "C" fn Position_startpos() -> *mut Self
#[no_mangle]pub extern "C" fn Position_startpos() -> *mut Self
C interface of Position::startpos.
source#[no_mangle]pub unsafe extern "C" fn Position_destruct(ptr: *mut Self)
#[no_mangle]pub unsafe extern "C" fn Position_destruct(ptr: *mut Self)
sourcepub fn arbitrary_position(p: PartialPosition) -> Self
pub fn arbitrary_position(p: PartialPosition) -> Self
Creates a Position with its initial position p.
source#[export_name = "Position_side_to_move"]pub extern "C" fn side_to_move(&self) -> Color
#[export_name = "Position_side_to_move"]pub extern "C" fn side_to_move(&self) -> Color
Finds which player is to move.
Examples:
let mut pos = Position::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);source#[export_name = "Position_hand_of_a_player"]pub extern "C" fn hand_of_a_player(&self, color: Color) -> Hand
#[export_name = "Position_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
👎 Deprecated since 0.1.2: This function can create inconsistent states. It will be removed in 0.2.0.
pub fn hand_of_a_player_mut(&mut self, color: Color) -> &mut Hand
This function can create inconsistent states. It will be removed in 0.2.0.
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 = "Position_ply"]pub extern "C" fn ply(&self) -> u16
#[export_name = "Position_ply"]pub extern "C" fn ply(&self) -> u16
Finds how many moves were made.
source#[no_mangle]pub extern "C" fn Position_piece_at(
&self,
square: Square
) -> OptionPiece
#[no_mangle]pub extern "C" fn Position_piece_at(
&self,
square: Square
) -> OptionPiece
C interface to Position::piece_at.
sourcepub fn piece_set(&mut self, square: Square, piece: Option<Piece>)
👎 Deprecated since 0.1.2: This function can create inconsistent states. It will be removed in 0.2.0.
pub fn piece_set(&mut self, square: Square, piece: Option<Piece>)
This function can create inconsistent states. It will be removed in 0.2.0.
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.
source#[export_name = "Position_occupied_bitboard"]pub extern "C" fn occupied_bitboard(&self) -> BitboardⓘNotable traits for Bitboardimpl Iterator for Bitboard type Item = Square;
#[export_name = "Position_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 = "Position_vacant_bitboard"]pub extern "C" fn vacant_bitboard(&self) -> BitboardⓘNotable traits for Bitboardimpl Iterator for Bitboard type Item = Square;
#[export_name = "Position_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 = "Position_player_bitboard"]pub extern "C" fn player_bitboard(&self, color: Color) -> BitboardⓘNotable traits for Bitboardimpl Iterator for Bitboard type Item = Square;
#[export_name = "Position_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 = "Position_piece_bitboard"]pub extern "C" fn piece_bitboard(&self, piece: Piece) -> BitboardⓘNotable traits for Bitboardimpl Iterator for Bitboard type Item = Square;
#[export_name = "Position_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 = Position::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));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::Position;
assert_eq!(Position::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::Position;
assert_eq!(Position::startpos().last_compact_move(), None);sourcepub fn moves(&self) -> &[Move]
pub fn moves(&self) -> &[Move]
Returns all moves made so far.
Examples:
use shogi_core::Position;
assert_eq!(Position::startpos().moves(), []);Since: 0.1.2
source#[no_mangle]pub extern "C" fn Position_last_compact_move(
&self
) -> OptionCompactMove
#[no_mangle]pub extern "C" fn Position_last_compact_move(
&self
) -> OptionCompactMove
C interface to Position::last_compact_move.
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 = "Position_make_compact_move"]pub extern "C" fn make_compact_move(&mut self, mv: CompactMove) -> bool
#[export_name = "Position_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_owned(&self) -> String
pub fn to_sfen_owned(&self) -> String
Returns the SFEN representation of the current position.
Examples:
let pos = Position::startpos();
let s = pos.to_sfen_owned();
assert_eq!(
s,
"lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL b - 1",
);Trait Implementations
sourceimpl Ord for Position
Available on crate feature ord only.
impl Ord for Position
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 PartialOrd<Position> for Position
Available on crate feature ord only.
impl PartialOrd<Position> for Position
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 Position
impl StructuralEq for Position
impl StructuralPartialEq for Position
Auto Trait Implementations
impl RefUnwindSafe for Position
impl Send for Position
impl Sync for Position
impl Unpin for Position
impl UnwindSafe for Position
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