Enum pleco::core::Piece [−][src]
#[repr(u8)]pub enum Piece { None, WhitePawn, WhiteKnight, WhiteBishop, WhiteRook, WhiteQueen, WhiteKing, BlackPawn, BlackKnight, BlackBishop, BlackRook, BlackQueen, BlackKing, }
All possible Types of Pieces on a chessboard, for both colors.
For a representation of Only Pieces (with no color attached), see PieceType
Variants
None
WhitePawn
WhiteKnight
WhiteBishop
WhiteRook
WhiteQueen
WhiteKing
BlackPawn
BlackKnight
BlackBishop
BlackRook
BlackQueen
BlackKing
Methods
impl Piece
[src]
impl Piece
pub fn player(self) -> Option<Player>
[src]
pub fn player(self) -> Option<Player>
Returns the Player
of a piece, if any.
For an unsafe, "lossy" determination of a Player
, see Piece::player_lossy
.
Examples
use pleco::{Piece,Player}; let black_knight = Piece::BlackKnight; let player: Player = black_knight.player().unwrap(); assert_eq!(player, Player::Black);
The only discriminant that will return None
:
use pleco::{Piece,Player}; let piece = Piece::None; assert!(piece.player().is_none());
pub fn player_lossy(self) -> Player
[src]
pub fn player_lossy(self) -> Player
Returns the Player
of a Piece
.
Undefined Behavior
If the discriminant is Piece::None
, the returned Player
will be undefined. This method
must be used only when a returned Piece
is guaranteed to exist.
For a safer version of this method that accounts for an undetermined player,
see Piece::player
.
Examples
use pleco::{Piece,Player}; let white_pawn = Piece::WhitePawn; let player: Player = white_pawn.player_lossy(); assert_eq!(player, Player::White);
The following will invoke undefined behavior, so do not use it.
use pleco::{Piece,Player}; let piece = Piece::None; let fake_player: Player = piece.player_lossy();
pub fn type_of(self) -> PieceType
[src]
pub fn type_of(self) -> PieceType
Returns the PieceType
.
Examples
use pleco::{Piece,PieceType}; let white_queen = Piece::WhiteQueen; let no_piece = Piece::None; assert_eq!(white_queen.type_of(), PieceType::Q); assert_eq!(no_piece.type_of(), PieceType::None); let black_queen = Piece::BlackQueen; assert_eq!(white_queen.type_of(), black_queen.type_of());
pub fn player_piece(self) -> Option<(Player, PieceType)>
[src]
pub fn player_piece(self) -> Option<(Player, PieceType)>
Returns the Player
and PieceType
of this piece, if any. If the discriminant is
Piece::None
, None
will be returned.
For an unsafe, "lossy" determination of a Player
and Piece
,
see Piece::player_piece_lossy
.
Examples
use pleco::{Piece,PieceType,Player}; let white_queen = Piece::WhiteQueen; let (player, piece) = white_queen.player_piece().unwrap(); assert_eq!(piece, PieceType::Q); assert_eq!(player, Player::White);
pub fn player_piece_lossy(self) -> (Player, PieceType)
[src]
pub fn player_piece_lossy(self) -> (Player, PieceType)
Returns the Player
and PieceType
of a Piece
.
Undefined Behavior
If the discriminant is Piece::None
, the returned PieceType
will be correct, but
the Player
will be undefined.
For a safer version of this method that accounts for an undetermined player,
see Piece::player_piece
.
Examples
use pleco::{Piece,PieceType,Player}; let white_queen = Piece::WhiteQueen; let (player, piece) = white_queen.player_piece_lossy(); assert_eq!(piece, PieceType::Q); assert_eq!(player, Player::White);
Undefined behavior can be encountered by doing something akin to:
use pleco::{Piece,PieceType,Player}; let not_a_piece = Piece::None; let (wrong_player, piece) = not_a_piece.player_piece_lossy();
pub fn make(player: Player, piece_type: PieceType) -> Option<Piece>
[src]
pub fn make(player: Player, piece_type: PieceType) -> Option<Piece>
Creates a Piece
from a Player
and PieceType
. If the PieceType
is either
PieceType::All
or PieceType::None
, the returned value will be None
.
For an unsafe, lossy version of this method, see Piece::make_lossy
.
Examples
use pleco::{Piece,PieceType,Player}; let black_knight = Piece::make(Player::Black, PieceType::N).unwrap(); assert_eq!(black_knight.type_of(), PieceType::N); assert_eq!(black_knight.player().unwrap(), Player::Black); let illegal_piece = Piece::make(Player::White, PieceType::All); assert!(illegal_piece.is_none());
pub fn make_lossy(player: Player, piece_type: PieceType) -> Piece
[src]
pub fn make_lossy(player: Player, piece_type: PieceType) -> Piece
Creates a Piece
from a Player
and PieceType
.
Undefined Behavior
If the PieceType
is either PieceType::All
or PieceType::None
, undefined behavior will
follow. See Piece::make
for a safer version of this method.
Examples
use pleco::{Piece,PieceType,Player}; let black_knight = Piece::make_lossy(Player::Black, PieceType::N); assert_eq!(black_knight.type_of(), PieceType::N); assert_eq!(black_knight.player().unwrap(), Player::Black);
The following code snippet will give undefined behavior:
use pleco::{Piece,PieceType,Player}; let illegal_piece = Piece::make_lossy(Player::Black, PieceType::All);
pub fn character(self) -> Option<char>
[src]
pub fn character(self) -> Option<char>
Returns the character of a Piece
. If the Piece is Piece::None
, None
will be returned.
pub fn character_lossy(self) -> char
[src]
pub fn character_lossy(self) -> char
Trait Implementations
impl Copy for Piece
[src]
impl Copy for Piece
impl Clone for Piece
[src]
impl Clone for Piece
fn clone(&self) -> Piece
[src]
fn clone(&self) -> Piece
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl PartialEq for Piece
[src]
impl PartialEq for Piece
fn eq(&self, other: &Piece) -> bool
[src]
fn eq(&self, other: &Piece) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl Debug for Piece
[src]
impl Debug for Piece