Expand description
Represents a piece on the game board.
Fields
piece_type: PieceType
color: Color
Implementations
sourceimpl Piece
impl Piece
sourcepub fn from_sfen(c: char) -> Option<Piece>
pub fn from_sfen(c: char) -> Option<Piece>
Creates a new instance of Piece
from SFEN formatted string.
sourcepub fn promote(self) -> Option<Piece>
pub fn promote(self) -> Option<Piece>
Returns an instance of Piece
after promotion.
Examples
use shuuro::{Color, PieceType, Piece};
let pc1 = Piece{piece_type: PieceType::Pawn, color: Color::Black};
let pc2 = Piece{piece_type: PieceType::Queen, color: Color::Black};
assert_eq!(Some(pc2), pc1.promote());
assert_eq!(None, pc2.promote());
sourcepub fn unpromote(self) -> Option<Piece>
pub fn unpromote(self) -> Option<Piece>
Returns an instance of Piece
before promotion.
Examples
use shuuro::{Color, PieceType, Piece};
let pc1 = Piece{piece_type: PieceType::Pawn, color: Color::Black};
let pc2 = Piece{piece_type: PieceType::Queen, color: Color::Black};
assert_eq!(Some(pc1), pc2.unpromote());
assert_eq!(None, pc1.unpromote());
sourcepub fn flip(self) -> Piece
pub fn flip(self) -> Piece
Returns an instance of Piece
with the reversed color.
Examples
use shuuro::{Color, PieceType, Piece};
let pc1 = Piece{piece_type: PieceType::Pawn, color: Color::Black};
let pc2 = Piece{piece_type: PieceType::Pawn, color: Color::White};
assert_eq!(pc2, pc1.flip());
assert_eq!(pc1, pc2.flip());
sourcepub fn is_placeable_at(self, sq: Square) -> bool
pub fn is_placeable_at(self, sq: Square) -> bool
Tests if it is legal to place this piece at the given square.
Trait Implementations
impl Copy for Piece
impl Eq for Piece
impl StructuralEq for Piece
impl StructuralPartialEq for Piece
Auto Trait Implementations
impl RefUnwindSafe for Piece
impl Send for Piece
impl Sync for Piece
impl Unpin for Piece
impl UnwindSafe for Piece
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
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
🔬 This is a nightly-only experimental API. (
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more