Skip to main content

Board

Struct Board 

Source
pub struct Board { /* private fields */ }
Expand description

A struct that represents a chess board The board is represented by bitboards of each piece (color and type)

Implementations§

Source§

impl Board

Source

pub fn new(fen: &str) -> Result<Board, FenError>

Creates a new board from a FEN string

§Arguments
  • fen: A FEN string representing the board
§Returns
  • Ok(Board): A new board with the position represented by the FEN string
  • Err(FenError): If the FEN string is invalid
Source

pub fn empty() -> Board

Creates a new empty board

§Returns

A new empty board

Source

pub fn from_fen(fen: &str) -> Result<Board, FenError>

Creates a new board from a FEN string

§Arguments
  • fen: A FEN string representing the board
§Returns

A Result<Board, FenError> object

  • Ok(Board): A new board with the position represented by the FEN string
  • Err(FenError): If the FEN string is invalid
Source

pub fn is_ocupied(&self, pos: &Position) -> bool

Checks if a position is occupied by a piece

§Arguments
  • pos: The position to check
§Returns

Whether the position is occupied by a piece

Source

pub fn get_piece(&self, pos: &Position) -> Option<Piece>

Gets the piece at a position

§Arguments
  • pos: The position to get the piece
§Returns

The piece at the position or None if the position is empty

Source

pub fn set_piece( &mut self, piece: Piece, pos: &Position, ) -> Result<(), PositionOccupiedError>

Sets a piece at a position

§Arguments
  • piece: The piece to set
  • pos: The position to set the piece
§Returns
  • Ok(()): If the piece was set successfully
  • Err(PositionOccupiedError): If the position is already occupied
Source

pub fn delete_piece( &mut self, pos: &Position, ) -> Result<Piece, PositionEmptyError>

Deletes a piece at a position

§Arguments
  • pos: The position to delete the piece
§Returns
  • Ok(Piece): The piece that was deleted
  • Err(PositionEmptyError): If the position is empty
Source

pub fn find(&self, piece_type: PieceType, color: Color) -> Vec<Position>

Finds all pieces of a certain type and color

§Arguments
  • piece_type: The type of the piece
  • color: The color of the piece
§Returns

A vector of positions of the pieces

Source

pub fn find_all(&self, color: Color) -> Vec<Position>

Finds all pieces of a certain color

§Arguments
  • color: The color of the pieces
§Returns

A vector of positions of the pieces

Source

pub fn move_piece( &mut self, from: &Position, to: &Position, ) -> Result<(), PositionEmptyError>

Moves a piece from one position to another

§Arguments
  • from: The position to move the piece from
  • to: The position to move the piece to
§Returns
  • Ok(()): If the piece was moved successfully
  • Err(PositionEmptyError): If the start position is empty
Source

pub fn is_attacked(&self, pos: Position, color: Color) -> bool

Checks if a position is attacked by a certain color

§Arguments
  • pos: The position to check
  • color: The color of the attacking pieces
§Returns

Whether the position is attacked or not

Source

pub fn can_move( &self, start_pos: &Position, end_pos: &Position, ) -> Result<bool, PositionEmptyError>

Checks if a piece can move without considering checks

§Arguments
  • start_pos: The position of the piece to move
  • end_pos: The position of the piece to capture
§Returns
  • Ok(bool): Whether the piece can move acording to its movement rules
  • Err(PositionEmptyError): If the start position is empty
Source

pub fn is_attacking( &self, start_pos: &Position, end_pos: &Position, ) -> Result<bool, PositionEmptyError>

Checks if a piece of a postion is attacking a position The function does not check if the move is legal It only checks if the piece is attacking the position according to its movement rules

§Arguments
  • start_pos: The position of the piece to move
  • end_pos: The position of the piece to capture
§Returns
  • Ok(bool): Whether the piece is attacking the position
  • Err(PositionEmptyError): If the start position is empty
Source

pub fn piece_between( &self, from: &Position, to: &Position, ) -> Result<bool, PositionBetweenError>

Checks if there is a piece between two positions

§Arguments
  • from: The starting position
  • to: The ending position
§Returns
  • Ok(bool): Whether there is a piece between the two positions
  • Err(PositionBetweenError): If the positions are not aligned

Trait Implementations§

Source§

impl Clone for Board

Source§

fn clone(&self) -> Board

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 Board

Source§

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

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

impl Default for Board

Source§

fn default() -> Board

Creates a new board with the default starting position

§Returns

A new board with the default starting position

Source§

impl Display for Board

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Board

§

impl RefUnwindSafe for Board

§

impl Send for Board

§

impl Sync for Board

§

impl Unpin for Board

§

impl UnsafeUnpin for Board

§

impl UnwindSafe for Board

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V