pub struct Position { /* private fields */ }
Implementations§
Source§impl Position
impl Position
Sourcepub const fn king_pos(color: Color) -> Self
pub const fn king_pos(color: Color) -> Self
Return the starting position for a given color’s king.
Sourcepub const fn queen_pos(color: Color) -> Self
pub const fn queen_pos(color: Color) -> Self
Return the starting position for a given color’s queen.
Sourcepub const fn new(row: i32, col: i32) -> Self
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)
Sourcepub fn pgn(s: &str) -> Result<Self, String>
pub fn pgn(s: &str) -> Result<Self, String>
Parse a position from PGN. This simply just supports positions like
e4
and D8
.
Sourcepub fn is_on_board(&self) -> bool
pub fn is_on_board(&self) -> bool
Is this position a valid spot on the board?
Sourcepub fn is_off_board(&self) -> bool
pub fn is_off_board(&self) -> bool
Is this position NOT a valid spot on the board?
Sourcepub fn get_row(&self) -> i32
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.
pub fn get_col(&self) -> i32
Sourcepub fn is_diagonal_to(&self, other: Self) -> bool
pub fn is_diagonal_to(&self, other: Self) -> bool
Is this position diagonal to another position?
Sourcepub fn is_orthogonal_to(&self, other: Self) -> bool
pub fn is_orthogonal_to(&self, other: Self) -> bool
Is this position orthogonal to another position?
Sourcepub fn is_adjacent_to(&self, other: Self) -> bool
pub fn is_adjacent_to(&self, other: Self) -> bool
Is this position adjacent to another position?
Adjacent positions have either:
- A diagonal distance of one from each other
- An orthogonal distance of one from each other
Sourcepub fn is_below(&self, other: Self) -> bool
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.
Sourcepub fn is_above(&self, other: Self) -> bool
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.
Sourcepub fn is_left_of(&self, other: Self) -> bool
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.
Sourcepub fn is_right_of(&self, other: Self) -> bool
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.
Sourcepub fn next_below(&self) -> Self
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!
Sourcepub fn next_above(&self) -> Self
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!
Sourcepub fn pawn_up(&self, ally_color: Color) -> Self
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!
Sourcepub fn pawn_back(&self, ally_color: Color) -> Self
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!
Sourcepub fn next_left(&self) -> Self
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!
Sourcepub fn next_right(&self) -> Self
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!
Sourcepub fn is_starting_pawn(&self, color: Color) -> bool
pub fn is_starting_pawn(&self, color: Color) -> bool
Is this pawn on the starting rank for the respective player?
Sourcepub fn is_kingside_rook(&self) -> bool
pub fn is_kingside_rook(&self) -> bool
Is this the starting position of the kingside rook?
Sourcepub fn is_queenside_rook(&self) -> bool
pub fn is_queenside_rook(&self) -> bool
Is this the starting position of the queenside rook?
Sourcepub fn diagonals_to(&self, to: Self) -> Vec<Self>
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.
Sourcepub fn orthogonals_to(&self, to: Self) -> Vec<Self>
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.