[][src]Struct chess_engine::Position

pub struct Position { /* fields omitted */ }

Implementations

impl Position[src]

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

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

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

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

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

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)

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

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

pub fn is_on_board(&self) -> bool[src]

Is this position a valid spot on the board?

pub fn is_off_board(&self) -> bool[src]

Is this position NOT a valid spot on the board?

pub fn get_row(&self) -> i32[src]

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

pub fn get_col(&self) -> i32[src]

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

Is this position diagonal to another position?

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

Is this position orthogonal to another position?

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

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

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

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.

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

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.

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

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.

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

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.

pub fn next_below(&self) -> Self[src]

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!

pub fn next_above(&self) -> Self[src]

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!

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

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!

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

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!

pub fn next_left(&self) -> Self[src]

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!

pub fn next_right(&self) -> Self[src]

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!

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

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

pub fn is_kingside_rook(&self) -> bool[src]

Is this the starting position of the kingside rook?

pub fn is_queenside_rook(&self) -> bool[src]

Is this the starting position of the queenside rook?

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

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.

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

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.

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

Trait Implementations

impl Clone for Position[src]

impl Copy for Position[src]

impl Debug for Position[src]

impl Display for Position[src]

impl Eq for Position[src]

impl Ord for Position[src]

impl PartialEq<Position> for Position[src]

impl PartialOrd<Position> for Position[src]

impl StructuralEq for Position[src]

impl StructuralPartialEq for Position[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.