pub struct Piece {
pub color: Color,
pub piece_type: PieceType,
}
Expand description
Represents a piece on the board with a color and a piece type
§Examples
use chess_lab::logic::Piece;
use chess_lab::constants::{Color, PieceType};
let piece = Piece::new(Color::White, PieceType::Pawn);
assert_eq!(piece.color, Color::White);
assert_eq!(piece.piece_type, PieceType::Pawn);
assert_eq!(piece.to_string(), "P");
Fields§
§color: Color
§piece_type: PieceType
Implementations§
Source§impl Piece
impl Piece
Sourcepub fn new(color: Color, piece_type: PieceType) -> Piece
pub fn new(color: Color, piece_type: PieceType) -> Piece
Creates a new piece with a given color and piece type
§Arguments
color
: The color of the piecepiece_type
: The type of the piece
§Returns
A new piece with the given color and piece type
§Examples
use chess_lab::logic::Piece;
use chess_lab::constants::{Color, PieceType};
let piece = Piece::new(Color::White, PieceType::Pawn);
assert_eq!(piece.color, Color::White);
assert_eq!(piece.piece_type, PieceType::Pawn);
Sourcepub fn from_fen(char: char) -> Piece
pub fn from_fen(char: char) -> Piece
Creates a new piece from a FEN character
§Arguments
char
: The FEN character representing the piece
§Returns
A new piece with the color and piece type represented by the FEN character
§Examples
use chess_lab::logic::Piece;
use chess_lab::constants::{Color, PieceType};
let piece = Piece::from_fen('P');
assert_eq!(piece.color, Color::White);
assert_eq!(piece.piece_type, PieceType::Pawn);
Trait Implementations§
impl Copy for Piece
impl StructuralPartialEq for Piece
Auto Trait Implementations§
impl Freeze for Piece
impl RefUnwindSafe for Piece
impl Send for Piece
impl Sync for Piece
impl Unpin for Piece
impl UnwindSafe for Piece
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more