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

Methods

impl Piece
[src]

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());

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();

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());

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);

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();

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());

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);

Returns the character of a Piece. If the Piece is Piece::None, None will be returned.

Returns the character of a Piece.

Panics

If the Piece is Piece::None, a panic will occur.

Trait Implementations

impl Copy for Piece
[src]

impl Clone for Piece
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl PartialEq for Piece
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl Debug for Piece
[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl Send for Piece

impl Sync for Piece