Struct hexe_core::board::piece_map::PieceMap
[−]
[src]
#[repr(C)]pub struct PieceMap(_);
A mapping of sixty-four squares to pieces.
This allows for faster lookups than possible with bitboards.
Note: PieceMap::default()
returns an empty piece map. Use
PieceMap::STANDARD
to get a mapping for
standard chess.
Methods
impl PieceMap
[src]
pub const EMPTY: PieceMap
EMPTY: PieceMap = PieceMap(Inner{array: [NONE; SQUARE_NUM],})
An empty piece map.
pub const STANDARD: PieceMap
STANDARD: PieceMap = PieceMap(Inner{array: tables::STANDARD,})
The piece map for standard chess.
pub fn new() -> PieceMap
[src]
Creates an empty piece map.
pub fn from_fen(fen: &str) -> Option<PieceMap>
[src]
Attempts to create a piece map from the fen string.
pub fn filled(piece: Piece) -> PieceMap
[src]
Creates a map with all squares populated by piece
.
pub fn from_init<F>(init: F) -> PieceMap where
F: FnMut(Square) -> Option<Piece>,
[src]
F: FnMut(Square) -> Option<Piece>,
Creates a new piece map by instantiating each slot with the provided initializer.
Examples
Basic usage:
let piece_map = PieceMap::from_init(|sq| { /* ... */ });
pub fn reverse(&mut self)
[src]
Reverses the square mapping.
Examples
Basic usage:
let mut map = PieceMap::new(); let piece = Piece::WhitePawn; map.insert(Square::A1, piece); map.reverse(); assert_eq!(map[Square::H8], piece);
pub fn mirror_horizontal(&mut self)
[src]
Mirrors the map across the horizontal axis of a chess board.
pub fn mirror_vertical(&mut self)
[src]
Mirrors the map across the vertical axis of a chess board.
pub fn first(&self) -> Option<(Square, &Piece)>
[src]
Returns the first square and piece pair in the map.
pub fn first_mut(&mut self) -> Option<(Square, &mut Piece)>
[src]
Returns the first square and mutable piece pair in the map.
pub fn last(&self) -> Option<(Square, &Piece)>
[src]
Returns the last square and piece pair in the map.
pub fn last_mut(&mut self) -> Option<(Square, &mut Piece)>
[src]
Returns the last square and mutable piece pair in the map.
pub fn fill_rank(&mut self, r: Rank, pc: Piece)
[src]
Efficiently fills the rank entirely with the given piece.
pub fn insert(&mut self, sq: Square, pc: Piece) -> Option<Piece>
[src]
Inserts the piece at a square, returning the previous one if any.
pub fn remove(&mut self, sq: Square) -> Option<Piece>
[src]
Removes the piece at a square.
pub fn swap<T: Swap>(&mut self, i: T, j: T)
[src]
Swaps two values in the map.
pub fn relocate(&mut self, from: Square, to: Square)
[src]
Takes the piece at the square and moves it.
pub fn capture(&mut self, from: Square, to: Square) -> Option<Piece>
[src]
Performs a capture of the piece at to
via the piece at from
.
If the squares are the same, then this will simply perform a removal.
pub fn en_passant(&mut self, from: Square, to: Square) -> Option<Piece>
[src]
Performs an en passant capture of the piece on the same file as to
and
the same rank as from
, via the piece at from
.
There are no checks made regarding whether from
and to
are legal en
passant squares. The capture is performed with no assumptions. This also
does not check whether the destination square contains a piece. If it
does, it will be replaced by whichever value is at from
.
Examples
Basic usage:
let mut map = PieceMap::STANDARD; map.relocate(D2, D5); map.relocate(C7, C5); assert_eq!(map[D5], WhitePawn); assert_eq!(map[C5], BlackPawn); let pc = map.en_passant(D5, C6); assert_eq!(pc, Some(BlackPawn)); assert_eq!(map.get(C5), None);
pub fn castle(&mut self, right: Right)
[src]
Performs a blind castle of the pieces for the castling right.
Under legal castling circumstances, this method makes it so that squares
involved with castling using right
are in a correct state post-castle.
pub fn extend_from<F>(&mut self, f: F) where
F: FnMut(Square) -> Option<Piece>,
[src]
F: FnMut(Square) -> Option<Piece>,
Inserts all pieces for which the function returns Some
.
pub fn retain<F>(&mut self, f: F) where
F: FnMut(Square, &mut Piece) -> bool,
[src]
F: FnMut(Square, &mut Piece) -> bool,
Retains only the elements specified by the predicate.
pub fn clear(&mut self)
[src]
Clears the map, removing all pieces.
pub fn clear_file(&mut self, file: File)
[src]
Removes all pieces from the given file.
pub fn clear_rank(&mut self, rank: Rank)
[src]
Removes all pieces from the given rank.
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 self.len() == 0
.
pub fn len(&self) -> usize
[src]
Returns the total number of pieces in self
.
This operation is performed in O(n) time. It is recommended to store the result if it is used repeatedly.
pub fn count(&self, piece: Piece) -> usize
[src]
Returns the number of occurrences of piece
in self
.
This operation is performed in O(n) time. It is recommended to store the result if it is used repeatedly.
pub fn contains<'a, T: Contained<&'a Self>>(&'a self, value: T) -> bool
[src]
Returns whether the map contains the value.
Examples
Basic usage:
let sq = Square::B7; let pc = Piece::WhiteRook; let mut map = PieceMap::new(); map.insert(sq, pc); assert!(map.contains(sq)); assert!(map.contains(pc));
pub fn rank_contains(&self, rank: Rank, pc: Piece) -> bool
[src]
Returns whether the rank contains the piece.
pub fn find(&self, pc: Piece) -> Option<Square>
[src]
Returns the first square for the piece.
pub fn rfind(&self, pc: Piece) -> Option<Square>
[src]
Returns the last square for the piece.
pub fn entry(&mut self, sq: Square) -> Entry
[src]
Gets the given square's corresponding entry in the map for in-place manipulation.
pub fn get(&self, sq: Square) -> Option<&Piece>
[src]
Returns a reference to the piece at a square, if any.
pub fn get_mut(&mut self, sq: Square) -> Option<&mut Piece>
[src]
Returns a mutable reference to the piece at a square, if any.
pub unsafe fn get_unchecked(&self, sq: Square) -> &Piece
[src]
Returns a reference to the piece at a square without checking.
Safety
Calling this method when there's no piece at the given square will produce undefined behavior. Use with caution.
pub unsafe fn get_unchecked_mut(&mut self, sq: Square) -> &mut Piece
[src]
Returns a mutable reference to the piece at a square without checking.
Safety
Calling this method when there's no piece at the given square will produce undefined behavior. Use with caution.
pub fn color_at(&self, sq: Square) -> Option<Color>
[src]
Returns the color of the piece at the given square, if any.
pub fn color_at_unchecked(&self, sq: Square) -> Color
[src]
Returns the color of the piece at the square without checking whether a valid piece exists there.
Because of how Color
is encoded in Piece
, this is not an unsafe
operation. If the square is empty, the returned color is White
.
However, errors and bugs may arise if this is used on an empty square.
pub fn role_at(&self, sq: Square) -> Option<Role>
[src]
Returns the role of the piece at the given square, if any.
pub fn map_str<T, F: FnOnce(&mut str) -> T>(&self, f: F) -> T
[src]
Returns the result of applying a function to a mutable string
representation of self
.
This method has the same benefits as Square::map_str
Examples
Note: PieceMap
implements Display
, thus it can be printed
directly without using this method.
let map = PieceMap::STANDARD; let exp = "r n b q k b n r\n\ p p p p p p p p\n\ . . . . . . . .\n\ . . . . . . . .\n\ . . . . . . . .\n\ . . . . . . . .\n\ P P P P P P P P\n\ R N B Q K B N R"; map.map_str(|s| assert_eq!(s, exp));
pub fn map_fen<T, F: FnOnce(&mut str) -> T>(&self, f: F) -> T
[src]
Returns the result of applying a function to a FEN string
representation of self
.
pub fn to_fen(&self) -> String
[src]
Returns an owned FEN string representation of self
.
ⓘImportant traits for Iter<'a>pub fn iter(&self) -> Iter
[src]
Returns an iterator visiting all square-piece pairs in order.
ⓘImportant traits for IterMut<'a>pub fn iter_mut(&mut self) -> IterMut
[src]
Returns an iterator visiting all square-piece pairs mutably in order.
pub fn as_bytes(&self) -> &[u8; 64]
[src]
Returns a view into the bytes of the map.
Values
- Bytes with values less than 12 refer to a valid
Piece
instance. - Empty slots have a value of 12.
You may safely assume that that no values greater than 12 exist.
pub unsafe fn as_bytes_mut(&mut self) -> &mut [u8; 64]
[src]
Returns a mutable view into the bytes of the map.
For more information, see as_bytes
.
Safety
Internal operations rely on certain assumptions about the contents of this buffer. Mutating these bytes such that piece values become invalid will cause undefined behavior.
Trait Implementations
impl<'a> From<&'a PieceMap> for MultiBoard
[src]
fn from(map: &PieceMap) -> MultiBoard
[src]
Performs the conversion.
impl<'a> IntoIterator for &'a PieceMap
[src]
type Item = (Square, &'a Piece)
The type of the elements being iterated over.
type IntoIter = Iter<'a>
Which kind of iterator are we turning this into?
ⓘImportant traits for Iter<'a>fn into_iter(self) -> Iter<'a>
[src]
Creates an iterator from a value. Read more
impl<'a> IntoIterator for &'a mut PieceMap
[src]
type Item = (Square, &'a mut Piece)
The type of the elements being iterated over.
type IntoIter = IterMut<'a>
Which kind of iterator are we turning this into?
ⓘImportant traits for IterMut<'a>fn into_iter(self) -> IterMut<'a>
[src]
Creates an iterator from a value. Read more
impl FromUnchecked<[u8; 64]> for PieceMap
[src]
impl Clone for PieceMap
[src]
fn clone(&self) -> PieceMap
[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 PartialEq for PieceMap
[src]
fn eq(&self, other: &PieceMap) -> 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 Eq for PieceMap
[src]
impl Default for PieceMap
[src]
impl Hash for PieceMap
[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<Square> for PieceMap
[src]
type Output = Piece
The returned type after indexing.
fn index(&self, sq: Square) -> &Piece
[src]
Performs the indexing (container[index]
) operation.
impl IndexMut<Square> for PieceMap
[src]
fn index_mut(&mut self, sq: Square) -> &mut Piece
[src]
Performs the mutable indexing (container[index]
) operation.
impl Debug for PieceMap
[src]
fn fmt(&self, f: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl Display for PieceMap
[src]
fn fmt(&self, f: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl FromIterator<(Square, Piece)> for PieceMap
[src]
fn from_iter<T: IntoIterator<Item = (Square, Piece)>>(iter: T) -> PieceMap
[src]
Creates a value from an iterator. Read more
impl Extend<(Square, Piece)> for PieceMap
[src]
fn extend<T: IntoIterator<Item = (Square, Piece)>>(&mut self, iter: T)
[src]
Extends a collection with the contents of an iterator. Read more
impl<'a> Contained<&'a PieceMap> for Square
[src]
fn contained_in(self, map: &PieceMap) -> bool
[src]
Returns whether self
is contained in other
.
impl<'a> Contained<&'a PieceMap> for Piece
[src]
fn contained_in(self, map: &PieceMap) -> bool
[src]
Returns whether self
is contained in other
.