pub struct Position {
pub col: u8,
pub row: u8,
}
Expand description
Represents a position on the board. The position is represented by a column and a row.
§Examples
use chess_lab::constants::Position;
let pos = Position::new(0, 0);
assert_eq!(pos.to_string(), "a1");
let pos = Position::from_string("a1");
assert_eq!(pos.col, 0);
assert_eq!(pos.row, 0);
Fields§
§col: u8
§row: u8
Implementations§
Source§impl Position
impl Position
Sourcepub fn new(col: u8, row: u8) -> Position
pub fn new(col: u8, row: u8) -> Position
Creates a new position
§Arguments
col
: The column of the position (between 0 and 7)row
: The row of the position (between 0 and 7)
§Returns
A new position
§Panics
Panics if the column or row is out of bounds
§Examples
use chess_lab::constants::Position;
let pos = Position::new(0, 0);
assert_eq!(pos.col, 0);
assert_eq!(pos.row, 0);
Sourcepub fn from_string(s: &str) -> Position
pub fn from_string(s: &str) -> Position
Creates a new position from a string
§Arguments
s
: The string representation of the position
§Returns
A new position
§Panics
Panics if the string is not a valid position
§Examples
use chess_lab::constants::Position;
let pos = Position::from_string("a1");
assert_eq!(pos.col, 0);
assert_eq!(pos.row, 0);
Sourcepub fn to_bitboard(&self) -> u64
pub fn to_bitboard(&self) -> u64
Sourcepub fn from_bitboard(bitboard: u64) -> Vec<Position>
pub fn from_bitboard(bitboard: u64) -> Vec<Position>
Sourcepub fn direction(&self, other: &Position) -> (i8, i8)
pub fn direction(&self, other: &Position) -> (i8, i8)
Gets the direction between two positions
§Arguments
other
: The other position
§Returns
The direction between the two positions
§Examples
use chess_lab::constants::Position;
let pos1 = Position::new(0, 0);
let pos2 = Position::new(1, 1);
let direction = pos1.direction(&pos2);
assert_eq!(direction, (1, 1));
Trait Implementations§
impl Copy for Position
impl StructuralPartialEq for Position
Auto Trait Implementations§
impl Freeze for Position
impl RefUnwindSafe for Position
impl Send for Position
impl Sync for Position
impl Unpin for Position
impl UnwindSafe for Position
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more