Struct hexe_core::board::MultiBoard
[−]
[src]
#[repr(C)]pub struct MultiBoard { /* fields omitted */ }
A full chess board, represented as multiple bitboard segments.
Methods
impl MultiBoard
[src]
pub const STANDARD: MultiBoard
STANDARD: MultiBoard = values::STANDARD
The board for standard chess.
pub fn clear(&mut self)
[src]
Clears the board of all pieces.
pub fn is_empty(&self) -> bool
[src]
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());
pub fn len(&self) -> usize
[src]
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);
ⓘImportant traits for Bitboardpub fn all_bits(&self) -> Bitboard
[src]
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());
ⓘImportant traits for Bitboardpub fn bitboard<T: Index>(&self, value: T) -> Bitboard
[src]
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));
ⓘImportant traits for Bitboardpub fn royals(&self) -> Bitboard
[src]
Returns the bits of the royal pieces, King and Queen.
pub fn first<T: Index>(&self, value: T) -> Option<Square>
[src]
Returns the first square that value
appears at, if any.
pub unsafe fn first_unchecked<T: Index>(&self, value: T) -> Square
[src]
Returns the first square that value
may appear at, without checking
whether it exists in self
.
pub fn last<T: Index>(&self, value: T) -> Option<Square>
[src]
Returns the last square that value
appears at, if any.
pub unsafe fn last_unchecked<T: Index>(&self, value: T) -> Square
[src]
Returns the last square that value
may appear at, without checking
whether it exists in self
.
pub fn count<T: Index>(&self, value: T) -> usize
[src]
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);
pub fn contains<T, U>(&self, bits: T, value: U) -> bool where
T: Into<Bitboard>,
U: Index,
[src]
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));
pub fn contains_any<T, U>(&self, bits: T, value: U) -> bool where
T: Into<Bitboard>,
U: Index,
[src]
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));
pub fn insert<T: Into<Bitboard>>(&mut self, bits: T, piece: Piece)
[src]
Inserts piece
at each square in bits
, removing any other pieces
that may be at bits
.
pub fn insert_unchecked<T: Into<Bitboard>>(&mut self, bits: T, piece: Piece)
[src]
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.
pub fn remove<T, U>(&mut self, bits: T, value: U) where
T: Into<Bitboard>,
U: Index,
[src]
T: Into<Bitboard>,
U: Index,
Removes each piece at bits
for value
.
pub fn remove_unchecked<T, U>(&mut self, bits: T, value: U) where
T: Into<Bitboard>,
U: Index,
[src]
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
.
pub fn remove_all<T: Into<Bitboard>>(&mut self, bits: T)
[src]
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)); }
pub fn split(&self) -> (&[Bitboard; 2], &[Bitboard; 6])
[src]
Returns references to the underlying bitboards for Color
and
Role
, respectively.
pub fn split_mut(&mut self) -> (&mut [Bitboard; 2], &mut [Bitboard; 6])
[src]
Returns mutable references to the underlying bitboards for Color
and
Role
, respectively.
pub fn is_attacked(&self, sq: Square, player: Color) -> bool
[src]
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)
.
pub fn castle(&mut self, right: Right)
[src]
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
impl Clone for MultiBoard
[src]
fn clone(&self) -> MultiBoard
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Eq for MultiBoard
[src]
impl PartialEq for MultiBoard
[src]
fn eq(&self, other: &Self) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl Default for MultiBoard
[src]
fn default() -> MultiBoard
[src]
Returns the "default value" for a type. Read more
impl AsRef<[u64]> for MultiBoard
[src]
impl AsMut<[u64]> for MultiBoard
[src]
impl AsRef<[Bitboard]> for MultiBoard
[src]
impl AsMut<[Bitboard]> for MultiBoard
[src]
impl<'a> From<&'a PieceMap> for MultiBoard
[src]
fn from(map: &PieceMap) -> MultiBoard
[src]
Performs the conversion.
impl Hash for MultiBoard
[src]
fn hash<H: Hasher>(&self, state: &mut H)
[src]
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl Index<Role> for MultiBoard
[src]
type Output = Bitboard
The returned type after indexing.
ⓘImportant traits for Bitboardfn index(&self, role: Role) -> &Bitboard
[src]
Performs the indexing (container[index]
) operation.
impl IndexMut<Role> for MultiBoard
[src]
ⓘImportant traits for Bitboardfn index_mut(&mut self, role: Role) -> &mut Bitboard
[src]
Performs the mutable indexing (container[index]
) operation.
impl Index<Color> for MultiBoard
[src]
type Output = Bitboard
The returned type after indexing.
ⓘImportant traits for Bitboardfn index(&self, color: Color) -> &Bitboard
[src]
Performs the indexing (container[index]
) operation.