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]

EMPTY: PieceMap = PieceMap(Inner{array: [NONE; SQUARE_NUM],})

An empty piece map.

STANDARD: PieceMap = PieceMap(Inner{array: tables::STANDARD,})

The piece map for standard chess.

[src]

Creates an empty piece map.

[src]

Attempts to create a piece map from the fen string.

[src]

Creates a map with all squares populated by piece.

[src]

Creates a new piece map by instantiating each slot with the provided initializer.

Examples

Basic usage:

let piece_map = PieceMap::from_init(|sq| {
    /* ... */
});

[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);

[src]

Mirrors the map across the horizontal axis of a chess board.

[src]

Mirrors the map across the vertical axis of a chess board.

[src]

Returns the first square and piece pair in the map.

[src]

Returns the first square and mutable piece pair in the map.

[src]

Returns the last square and piece pair in the map.

[src]

Returns the last square and mutable piece pair in the map.

[src]

Efficiently fills the rank entirely with the given piece.

[src]

Inserts the piece at a square, returning the previous one if any.

[src]

Removes the piece at a square.

[src]

Swaps two values in the map.

[src]

Takes the piece at the square and moves it.

[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.

[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);

[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.

[src]

Inserts all pieces for which the function returns Some.

[src]

Retains only the elements specified by the predicate.

[src]

Clears the map, removing all pieces.

[src]

Removes all pieces from the given file.

[src]

Removes all pieces from the given rank.

[src]

Returns whether self is empty.

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

[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.

[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.

[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));

[src]

Returns whether the rank contains the piece.

[src]

Returns the first square for the piece.

[src]

Returns the last square for the piece.

[src]

Gets the given square's corresponding entry in the map for in-place manipulation.

[src]

Returns a reference to the piece at a square, if any.

[src]

Returns a mutable reference to the piece at a square, if any.

[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.

[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.

[src]

Returns the color of the piece at the given square, if any.

[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.

[src]

Returns the role of the piece at the given square, if any.

[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));

[src]

Returns the result of applying a function to a FEN string representation of self.

[src]

Returns an owned FEN string representation of self.

Important traits for Iter<'a>
[src]

Returns an iterator visiting all square-piece pairs in order.

Important traits for IterMut<'a>
[src]

Returns an iterator visiting all square-piece pairs mutably in order.

[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.

[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]

[src]

Performs the conversion.

impl<'a> IntoIterator for &'a PieceMap
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Important traits for Iter<'a>
[src]

Creates an iterator from a value. Read more

impl<'a> IntoIterator for &'a mut PieceMap
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Important traits for IterMut<'a>
[src]

Creates an iterator from a value. Read more

impl FromUnchecked<[u8; 64]> for PieceMap
[src]

[src]

Performs the unchecked conversion.

impl Clone for PieceMap
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl PartialEq for PieceMap
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

1.0.0
[src]

This method tests for !=.

impl Eq for PieceMap
[src]

impl Default for PieceMap
[src]

[src]

Returns the "default value" for a type. Read more

impl Hash for PieceMap
[src]

[src]

Feeds this value into the given [Hasher]. Read more

1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl Index<Square> for PieceMap
[src]

The returned type after indexing.

[src]

Performs the indexing (container[index]) operation.

impl IndexMut<Square> for PieceMap
[src]

[src]

Performs the mutable indexing (container[index]) operation.

impl Debug for PieceMap
[src]

[src]

Formats the value using the given formatter. Read more

impl Display for PieceMap
[src]

[src]

Formats the value using the given formatter. Read more

impl FromIterator<(Square, Piece)> for PieceMap
[src]

[src]

Creates a value from an iterator. Read more

impl Extend<(Square, Piece)> for PieceMap
[src]

[src]

Extends a collection with the contents of an iterator. Read more

impl<'a> Contained<&'a PieceMap> for Square
[src]

[src]

Returns whether self is contained in other.

impl<'a> Contained<&'a PieceMap> for Piece
[src]

[src]

Returns whether self is contained in other.

Auto Trait Implementations

impl Send for PieceMap

impl Sync for PieceMap