#[repr(C)]pub struct MultiBoard { /* private fields */ }
Expand description
A full chess board, represented as multiple bitboard segments.
Implementations§
Source§impl MultiBoard
impl MultiBoard
Sourcepub const STANDARD: MultiBoard = values::STANDARD
pub const STANDARD: MultiBoard = values::STANDARD
The board for standard chess.
Sourcepub fn is_empty(&self) -> bool
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());
Sourcepub fn len(&self) -> usize
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);
Sourcepub fn all_bits(&self) -> Bitboard ⓘ
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());
Sourcepub fn bitboard<T: Index>(&self, value: T) -> Bitboard ⓘ
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));
Sourcepub fn first<T: Index>(&self, value: T) -> Option<Square>
pub fn first<T: Index>(&self, value: T) -> Option<Square>
Returns the first square that value
appears at, if any.
Sourcepub unsafe fn first_unchecked<T: Index>(&self, value: T) -> Square
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
.
Sourcepub fn last<T: Index>(&self, value: T) -> Option<Square>
pub fn last<T: Index>(&self, value: T) -> Option<Square>
Returns the last square that value
appears at, if any.
Sourcepub unsafe fn last_unchecked<T: Index>(&self, value: T) -> Square
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
.
Sourcepub fn count<T: Index>(&self, value: T) -> usize
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);
Sourcepub fn contains<T, U>(&self, bits: T, value: U) -> bool
pub fn contains<T, U>(&self, bits: T, value: U) -> bool
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));
Sourcepub fn contains_any<T, U>(&self, bits: T, value: U) -> bool
pub fn contains_any<T, U>(&self, bits: T, value: U) -> bool
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));
Sourcepub fn insert<T: Into<Bitboard>>(&mut self, bits: T, piece: Piece)
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
.
Sourcepub fn insert_unchecked<T: Into<Bitboard>>(&mut self, bits: T, piece: Piece)
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.
Sourcepub fn remove_unchecked<T, U>(&mut self, bits: T, value: U)
pub fn remove_unchecked<T, U>(&mut self, bits: T, value: U)
Performs a blind removal of value
at bits
.
It does not check whether other pieces that value
does not represent
are located at bits
.
Sourcepub fn remove_all<T: Into<Bitboard>>(&mut self, bits: T)
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));
}
Sourcepub fn split(&self) -> (&[Bitboard; 2], &[Bitboard; 6])
pub fn split(&self) -> (&[Bitboard; 2], &[Bitboard; 6])
Returns references to the underlying bitboards for Color
and
Role
, respectively.
Sourcepub fn split_mut(&mut self) -> (&mut [Bitboard; 2], &mut [Bitboard; 6])
pub fn split_mut(&mut self) -> (&mut [Bitboard; 2], &mut [Bitboard; 6])
Returns mutable references to the underlying bitboards for Color
and
Role
, respectively.
Sourcepub fn is_attacked(&self, sq: Square, player: Color) -> bool
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)
.
Sourcepub fn castle(&mut self, right: Right)
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
impl AsMut<[Bitboard]> for MultiBoard
Source§impl AsMut<[u64]> for MultiBoard
impl AsMut<[u64]> for MultiBoard
Source§impl AsRef<[Bitboard]> for MultiBoard
impl AsRef<[Bitboard]> for MultiBoard
Source§impl AsRef<[u64]> for MultiBoard
impl AsRef<[u64]> for MultiBoard
Source§impl Clone for MultiBoard
impl Clone for MultiBoard
Source§fn clone(&self) -> MultiBoard
fn clone(&self) -> MultiBoard
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more