Struct MultiBoard

Source
#[repr(C)]
pub struct MultiBoard { /* private fields */ }
Expand description

A full chess board, represented as multiple bitboard segments.

Implementations§

Source§

impl MultiBoard

Source

pub const STANDARD: MultiBoard = values::STANDARD

The board for standard chess.

Source

pub fn clear(&mut self)

Clears the board of all pieces.

Source

pub fn is_empty(&self) -> bool

Returns whether self is empty.

For much better performance and readability, is recommended to use this method over checking whether board.len() == 0.

§Examples

Basic usage:

use hexe_core::board::MultiBoard;

assert!(!MultiBoard::STANDARD.is_empty());
assert!(MultiBoard::default().is_empty());
Source

pub fn len(&self) -> usize

Returns the total number of pieces in self.

§Examples

Basic usage:

use hexe_core::board::MultiBoard;

let board = MultiBoard::STANDARD;
assert_eq!(board.len(), 32);
Source

pub fn all_bits(&self) -> Bitboard

Returns all bits of the pieces contained in self.

§Examples

Basic usage:

use hexe_core::board::MultiBoard;

let board = MultiBoard::STANDARD;
let value = 0xFFFF00000000FFFFu64;

assert_eq!(board.all_bits(), value.into());
Source

pub fn bitboard<T: Index>(&self, value: T) -> Bitboard

Returns the Bitboard for value in self.

§Examples

Basic usage:

use hexe_core::board::MultiBoard;
use hexe_core::prelude::*;

let board   = MultiBoard::STANDARD;
let king_sq = board.bitboard(Piece::WhiteKing).lsb();

assert_eq!(king_sq, Some(Square::E1));
Source

pub fn royals(&self) -> Bitboard

Returns the bits of the royal pieces, King and Queen.

Source

pub fn first<T: Index>(&self, value: T) -> Option<Square>

Returns the first square that value appears at, if any.

Source

pub unsafe fn first_unchecked<T: Index>(&self, value: T) -> Square

Returns the first square that value may appear at, without checking whether it exists in self.

Source

pub fn last<T: Index>(&self, value: T) -> Option<Square>

Returns the last square that value appears at, if any.

Source

pub unsafe fn last_unchecked<T: Index>(&self, value: T) -> Square

Returns the last square that value may appear at, without checking whether it exists in self.

Source

pub fn count<T: Index>(&self, value: T) -> usize

Returns the total number of value in self.

§Examples

Basic usage:

use hexe_core::board::MultiBoard;
use hexe_core::prelude::*;

let board = MultiBoard::STANDARD;

assert_eq!(board.count(Color::Black), 16);
assert_eq!(board.count(Piece::WhiteRook), 2);
assert_eq!(board.count(Role::Queen), 2);
Source

pub fn contains<T, U>(&self, bits: T, value: U) -> bool
where T: Into<Bitboard>, U: Index,

Returns whether value is contained at all squares in bits.

§Examples

Basic usage:

use hexe_core::board::MultiBoard;
use hexe_core::prelude::*;

let board = MultiBoard::STANDARD;

assert!(board.contains(Square::A2, Color::White));
assert!(board.contains(Square::C8, Role::Bishop));
assert!(board.contains(Rank::Seven, Piece::BlackPawn));
Source

pub fn contains_any<T, U>(&self, bits: T, value: U) -> bool
where T: Into<Bitboard>, U: Index,

Returns whether value is contained at any square in bits.

§Examples

Basic usage:

use hexe_core::board::MultiBoard;
use hexe_core::prelude::*;

let board = MultiBoard::STANDARD;

assert!(board.contains_any(File::B, Role::Knight));
assert!(board.contains_any(Rank::One, Role::King));
Source

pub fn insert<T: Into<Bitboard>>(&mut self, bits: T, piece: Piece)

Inserts piece at each square in bits, removing any other pieces that may be at bits.

Source

pub fn insert_unchecked<T: Into<Bitboard>>(&mut self, bits: T, piece: Piece)

Performs a blind insertion of piece at a each square in bits.

It does not check whether other pieces are located at bits. If the board may contain pieces at bits, then insert should be called instead.

Source

pub fn remove<T, U>(&mut self, bits: T, value: U)
where T: Into<Bitboard>, U: Index,

Removes each piece at bits for value.

Source

pub fn remove_unchecked<T, U>(&mut self, bits: T, value: U)
where T: Into<Bitboard>, U: Index,

Performs a blind removal of value at bits.

It does not check whether other pieces that value does not represent are located at bits.

Source

pub fn remove_all<T: Into<Bitboard>>(&mut self, bits: T)

Removes all pieces at bits.

§Examples

Basic usage:

use hexe_core::board::MultiBoard;
use hexe_core::prelude::*;

let mut board = MultiBoard::STANDARD;
let squares = [
    Square::A1,
    Square::C1,
    Square::F2,
];

for &square in squares.iter() {
    assert!(board[Color::White].contains(square));
    board.remove_all(square);
    assert!(!board[Color::White].contains(square));
}
Source

pub fn split(&self) -> (&[Bitboard; 2], &[Bitboard; 6])

Returns references to the underlying bitboards for Color and Role, respectively.

Source

pub fn split_mut(&mut self) -> (&mut [Bitboard; 2], &mut [Bitboard; 6])

Returns mutable references to the underlying bitboards for Color and Role, respectively.

Source

pub fn is_attacked(&self, sq: Square, player: Color) -> bool

Returns whether the square for player is being attacked.

This method does not check whether a piece for player actually exists at sq. To check for that, call board.contains(sq, player).

Source

pub fn castle(&mut self, right: Right)

Performs a blind castle of the pieces for the castling right.

§Invariants

Under legal castling circumstances, this method makes it so that squares involved with castling using right are in a correct state post-castle.

There are some cases where the board state may be invalidated if the above invariant isn’t correctly met:

  • If the king is not in its initial position, then a king will spawn both where it was expected to be, as well as where it would move to. The same will happen when the rook is not at its corner of the board.

  • If another rook is located where the castling rook is being moved to then both rooks will be removed.

  • If any other pieces are located at the involved squares, then other strange things will happen.

The above are all the result of properly defined behavior. They are just side effects of how the board is represented and this use of XOR.

§Examples

Basic usage:

use hexe_core::board::MultiBoard;
use hexe_core::prelude::*;

let mut board: MultiBoard = {
    /* create board */
};

board.castle(Right::WhiteQueen);
assert!(board.contains(Square::C1, Piece::WhiteKing));
assert!(board.contains(Square::D1, Piece::WhiteRook));
§Undo-Redo

Because this method internally uses XOR, it is its own inverse. If the involved king and rook sit at their destination squares, they will be moved back to their initial squares.

use hexe_core::board::MultiBoard;
use hexe_core::castle::Right;

let mut board: MultiBoard = {
    /* create board */
};

let right = Right::WhiteQueen;
let clone = board.clone();

board.castle(right);
board.castle(right);

assert!(board == clone);

Trait Implementations§

Source§

impl AsMut<[Bitboard]> for MultiBoard

Source§

fn as_mut(&mut self) -> &mut [Bitboard]

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl AsMut<[u64]> for MultiBoard

Source§

fn as_mut(&mut self) -> &mut [u64]

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl AsRef<[Bitboard]> for MultiBoard

Source§

fn as_ref(&self) -> &[Bitboard]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<[u64]> for MultiBoard

Source§

fn as_ref(&self) -> &[u64]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for MultiBoard

Source§

fn clone(&self) -> MultiBoard

Returns a copy 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 Default for MultiBoard

Source§

fn default() -> MultiBoard

Returns the “default value” for a type. Read more
Source§

impl<'a> From<&'a PieceMap> for MultiBoard

Source§

fn from(map: &PieceMap) -> MultiBoard

Converts to this type from the input type.
Source§

impl Hash for MultiBoard

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Index<Color> for MultiBoard

Source§

type Output = Bitboard

The returned type after indexing.
Source§

fn index(&self, color: Color) -> &Bitboard

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<Role> for MultiBoard

Source§

type Output = Bitboard

The returned type after indexing.
Source§

fn index(&self, role: Role) -> &Bitboard

Performs the indexing (container[index]) operation. Read more
Source§

impl IndexMut<Color> for MultiBoard

Source§

fn index_mut(&mut self, color: Color) -> &mut Bitboard

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<Role> for MultiBoard

Source§

fn index_mut(&mut self, role: Role) -> &mut Bitboard

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl PartialEq for MultiBoard

Source§

fn eq(&self, other: &Self) -> 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 Eq for MultiBoard

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, U> IntoUnchecked<U> for T
where U: FromUnchecked<T>,

Source§

unsafe fn into_unchecked(self) -> U

Performs the unchecked conversion.
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, 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.