pub struct Cell(/* private fields */);Expand description
Contents of square on a chess board
A square can be either empty or contain a piece of some given color.
This type is one compact and is only one byte long to facilitate compact chess board representation.
Implementations§
Source§impl Cell
impl Cell
Sourcepub const COUNT: usize = 13usize
pub const COUNT: usize = 13usize
Number of different possible indices of Cell
It exceeds maximum possible index by one.
Sourcepub const fn is_occupied(&self) -> bool
pub const fn is_occupied(&self) -> bool
Returns true if the cell contains a piece
Sourcepub const unsafe fn from_index_unchecked(val: usize) -> Cell
pub const unsafe fn from_index_unchecked(val: usize) -> Cell
Creates a cell from its index
§Safety
The behavior is undefined if the index is invalid (i.e. it is greater or equal than Cell::COUNT)
Sourcepub const fn from_index(val: usize) -> Cell
pub const fn from_index(val: usize) -> Cell
Creates a cell from its index
§Panics
The function panics if the index is invalid (i.e. it is greater or equal than Cell::COUNT)
Sourcepub const fn index(&self) -> usize
pub const fn index(&self) -> usize
Returns the index of the cell
Cell indices are stable between updates, and changing the index of some given cell is considered API breakage.
Sourcepub const fn from_parts(c: Color, p: Piece) -> Cell
pub const fn from_parts(c: Color, p: Piece) -> Cell
Creates a cell with a piece p of color c
Sourcepub const fn color(&self) -> Option<Color>
pub const fn color(&self) -> Option<Color>
Returns the color of the piece on the cell
If the cell is empty, returns None.
Sourcepub const fn piece(&self) -> Option<Piece>
pub const fn piece(&self) -> Option<Piece>
Returns the kind of the piece on the cell
If the cell is empty, returns None.
Sourcepub fn iter() -> impl Iterator<Item = Cell>
pub fn iter() -> impl Iterator<Item = Cell>
Iterates over all possible cells in ascending order of their indices
Sourcepub fn as_char(&self) -> char
pub fn as_char(&self) -> char
Returns a character representation of the cell
Unlike Cell::as_utf8_char, the representation is an ASCII character.
Sourcepub fn as_utf8_char(&self) -> char
pub fn as_utf8_char(&self) -> char
Converts a cell to a corresponding Unicode character