Add 'File::{left,right}'
This commit is contained in:
parent
6501466d3e
commit
2b4797ec47
|
@ -54,6 +54,18 @@ impl File {
|
||||||
self as usize
|
self as usize
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return the [File] to the left, as seen from white's perspective. Wraps around the board.
|
||||||
|
pub fn left(self) -> Self {
|
||||||
|
// SAFETY: we know the value is in-bounds, through masking
|
||||||
|
unsafe { Self::from_index_unchecked(self.index().wrapping_sub(1) & 7) }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return the [File] to the right, as seen from white's perspective. Wraps around the board.
|
||||||
|
pub fn right(self) -> Self {
|
||||||
|
// SAFETY: we know the value is in-bounds, through masking
|
||||||
|
unsafe { Self::from_index_unchecked(self.index().wrapping_add(1) & 7) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Turn a [File] into a [Bitboard] of all squares in that file.
|
/// Turn a [File] into a [Bitboard] of all squares in that file.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn into_bitboard(self) -> Bitboard {
|
pub fn into_bitboard(self) -> Bitboard {
|
||||||
|
@ -80,6 +92,20 @@ mod test {
|
||||||
assert_eq!(File::H.index(), 7);
|
assert_eq!(File::H.index(), 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn left() {
|
||||||
|
assert_eq!(File::A.left(), File::H);
|
||||||
|
assert_eq!(File::B.left(), File::A);
|
||||||
|
assert_eq!(File::H.left(), File::G);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn right() {
|
||||||
|
assert_eq!(File::A.right(), File::B);
|
||||||
|
assert_eq!(File::B.right(), File::C);
|
||||||
|
assert_eq!(File::H.right(), File::A);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn into_bitboard() {
|
fn into_bitboard() {
|
||||||
assert_eq!(File::A.into_bitboard(), Bitboard::FILES[0]);
|
assert_eq!(File::A.into_bitboard(), Bitboard::FILES[0]);
|
||||||
|
|
Loading…
Reference in a new issue