Struct Position

Source
pub struct Position { /* private fields */ }

Implementations§

Source§

impl Position

Source

pub const fn king_pos(color: Color) -> Self

Return the starting position for a given color’s king.

Source

pub const fn queen_pos(color: Color) -> Self

Return the starting position for a given color’s queen.

Source

pub const fn new(row: i32, col: i32) -> Self

Create a Position from its respective row or column number. The row and column numbers can be any of 0, 1, 2, 3, 4, 5, 6, or 7.

Examples:

  • A1 = Position::new(0, 0)
  • A8 = Position::new(7, 0)
  • H1 = Position::new(0, 7)
  • H8 = Position::new(7, 7)
Source

pub fn pgn(s: &str) -> Result<Self, String>

Parse a position from PGN. This simply just supports positions like e4 and D8.

Source

pub fn is_on_board(&self) -> bool

Is this position a valid spot on the board?

Source

pub fn is_off_board(&self) -> bool

Is this position NOT a valid spot on the board?

Source

pub fn get_row(&self) -> i32

Get the row number of the position. This can be any of 0, 1, 2, 3, 4, 5, 6, or 7.

Source

pub fn get_col(&self) -> i32

Source

pub fn is_diagonal_to(&self, other: Self) -> bool

Is this position diagonal to another position?

Source

pub fn is_orthogonal_to(&self, other: Self) -> bool

Is this position orthogonal to another position?

Source

pub fn is_adjacent_to(&self, other: Self) -> bool

Is this position adjacent to another position?

Adjacent positions have either:

  1. A diagonal distance of one from each other
  2. An orthogonal distance of one from each other
Source

pub fn is_below(&self, other: Self) -> bool

Is this position beneath another position on the board? Pieces “beneath” other pieces on the board have lower ranks.

So, for example, A7 is below A8.

Source

pub fn is_above(&self, other: Self) -> bool

Is this position above another position on the board? Pieces “above” other pieces on the board have higher ranks.

So, for example, A8 is above A8.

Source

pub fn is_left_of(&self, other: Self) -> bool

Is this position left of another position on the board? Pieces “left of” other pieces on the board have a lower lexigraphical column character.

So, for example, A8 is left of B8.

Source

pub fn is_right_of(&self, other: Self) -> bool

Is this position right of another position on the board? Pieces “right of” other pieces on the board have a higher lexigraphical column character.

So, for example, B8 is right of A8.

Source

pub fn next_below(&self) -> Self

Get the position directly below this position.

IMPORTANT NOTE: This will NOT check for positions off of the board! You could easily get an invalid position if you do not check with the is_on_board method!

Source

pub fn next_above(&self) -> Self

Get the position directly above this position.

IMPORTANT NOTE: This will NOT check for positions off of the board! You could easily get an invalid position if you do not check with the is_on_board method!

Source

pub fn pawn_up(&self, ally_color: Color) -> Self

Get the next square upwards from a respective player’s pawn.

IMPORTANT NOTE: This will NOT check for positions off of the board! You could easily get an invalid position if you do not check with the is_on_board method!

Source

pub fn pawn_back(&self, ally_color: Color) -> Self

Get the next square backwards from a respective player’s pawn.

IMPORTANT NOTE: This will NOT check for positions off of the board! You could easily get an invalid position if you do not check with the is_on_board method!

Source

pub fn next_left(&self) -> Self

Get the position directly left of this position.

IMPORTANT NOTE: This will NOT check for positions off of the board! You could easily get an invalid position if you do not check with the is_on_board method!

Source

pub fn next_right(&self) -> Self

Get the position directly right of this position.

IMPORTANT NOTE: This will NOT check for positions off of the board! You could easily get an invalid position if you do not check with the is_on_board method!

Source

pub fn is_starting_pawn(&self, color: Color) -> bool

Is this pawn on the starting rank for the respective player?

Source

pub fn is_kingside_rook(&self) -> bool

Is this the starting position of the kingside rook?

Source

pub fn is_queenside_rook(&self) -> bool

Is this the starting position of the queenside rook?

Source

pub fn diagonals_to(&self, to: Self) -> Vec<Self>

Get the list of positions from this position to another position, moving diagonally.

This does not include the from position, and includes the to position.

Source

pub fn orthogonals_to(&self, to: Self) -> Vec<Self>

Get the list of positions from this position to another position, moving orthogonally.

This does not include the from position, and includes the to position.

Source

pub fn is_knight_move(&self, other: Self) -> bool

Trait Implementations§

Source§

impl Clone for Position

Source§

fn clone(&self) -> Position

Returns a duplicate 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 Position

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Display for Position

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Ord for Position

Source§

fn cmp(&self, other: &Position) -> 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 Position

Source§

fn eq(&self, other: &Position) -> 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 Position

Source§

fn partial_cmp(&self, other: &Position) -> 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 Position

Source§

impl Eq for Position

Source§

impl StructuralPartialEq for Position

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.