Enum PieceKind

Source
#[repr(u8)]
pub enum PieceKind { Pawn = 0, Knight = 1, Bishop = 2, Rook = 3, Queen = 4, King = 5, }
Expand description

Represents the kind (or “role”) that a chess piece can be.

These have no Color associated with them. See Piece.

Variants§

§

Pawn = 0

§

Knight = 1

§

Bishop = 2

§

Rook = 3

§

Queen = 4

§

King = 5

Implementations§

Source§

impl PieceKind

Source

pub const COUNT: usize = 6usize

Number of piece variants.

Source

pub const fn all() -> [PieceKind; 6]

An array of all 6 PieceKinds.

In the order: Pawn, Knight, Bishop, Rook, Queen, King.

Source

pub const fn all_except_king() -> [PieceKind; 5]

An array of 5 non-King PieceKinds.

In the order: Pawn, Knight, Bishop, Rook, Queen.

Source

pub fn iter() -> impl Iterator<Item = PieceKind>

An iterator over all PieceKinds, starting with Pawn.

Source

pub fn from_bits(bits: u8) -> Result<PieceKind, Error>

Creates a new PieceKind from a set of bits.

bits must be [0,5].

§Panics

If bits is greater than 5.

§Example
let queen = PieceKind::from_bits(4);
assert!(queen.is_ok());
assert_eq!(queen.unwrap(), PieceKind::Queen);

let err = PieceKind::from_bits(42);
assert!(err.is_err());
Source

pub const fn from_bits_unchecked(bits: u8) -> PieceKind

Creates a new PieceKind from a set of bits, ignoring safety checks.

bits must be [0,5].

§Panics

If bits is greater than 5 when debug assertions are enabled.

§Example
let queen = PieceKind::from_bits_unchecked(4);
assert_eq!(queen, PieceKind::Queen);
Source

pub const fn bits(&self) -> u8

Fetches the internal bit value of this PieceKind.

Will always be [0,5].

§Example
let bits = PieceKind::Queen.bits();
assert_eq!(bits, 4);
Source

pub const fn index(&self) -> usize

Returns this PieceKind as a usize.

Useful for indexing into lists.

Will always be [0,5].

§Example
let index = PieceKind::Queen.index();
assert_eq!(index, 4);
Source

pub fn from_uci(kind: char) -> Result<PieceKind, Error>

Creates a new PieceKind from a character, according to the Universal Chess Interface notation.

Will return a anyhow::Error if kind is not a valid character.

§Example
let queen = PieceKind::from_uci('Q');
assert!(queen.is_ok());
assert_eq!(queen.unwrap(), PieceKind::Queen);
Source

pub const fn name(&self) -> &'static str

Fetches a human-readable name for this PieceKind.

§Example
let queen = PieceKind::Queen;
assert_eq!(queen.name(), "queen");
Source

pub const fn to_uci(&self) -> char

Converts this PieceKind to a character, according to the Universal Chess Interface notation.

Will always be a lowercase letter.

§Example
let queen = PieceKind::Queen;
assert_eq!(queen.to_uci(), 'q');
Source

pub const fn char(&self) -> char

Alias for PieceKind::to_uci.

Source

pub const fn as_str(&self) -> &'static str

Converts this PieceKind to a str, according to the Universal Chess Interface notation.

Will always be a lowercase letter.

§Example
let queen = PieceKind::Queen;
assert_eq!(queen.as_str(), "q");

Trait Implementations§

Source§

impl AsRef<str> for PieceKind

Source§

fn as_ref(&self) -> &str

Alias for Self::as_str.

Source§

impl Clone for PieceKind

Source§

fn clone(&self) -> PieceKind

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PieceKind

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Debug formatting displays a $type as its human-readable name and index value.

Source§

impl Display for PieceKind

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

By default, a $type displays as a lowercase char.

Source§

impl FromStr for PieceKind

Source§

fn from_str(s: &str) -> Result<PieceKind, <PieceKind as FromStr>::Err>

Does the same as Self::from_uci, but only if s is one character in length.

Source§

type Err = Error

The associated error which can be returned from parsing.
Source§

impl Hash for PieceKind

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Index<PieceKind> for Board

Source§

type Output = Bitboard

The returned type after indexing.
Source§

fn index(&self, index: PieceKind) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl IndexMut<PieceKind> for Board

Source§

fn index_mut(&mut self, index: PieceKind) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl Ord for PieceKind

Source§

fn cmp(&self, other: &PieceKind) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for PieceKind

Source§

fn eq(&self, other: &PieceKind) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for PieceKind

Source§

fn partial_cmp(&self, other: &PieceKind) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for PieceKind

Source§

impl Eq for PieceKind

Source§

impl StructuralPartialEq for PieceKind

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.