make bitboards public
This commit is contained in:
parent
5d1fa02280
commit
f45a384a96
3 changed files with 28 additions and 20 deletions
|
|
@ -1,19 +1,22 @@
|
|||
//! Sets of squares.
|
||||
|
||||
use crate::board::*;
|
||||
|
||||
use std::iter::ExactSizeIterator;
|
||||
use std::iter::FusedIterator;
|
||||
|
||||
/// A set of squares.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct Bitboard(pub(crate) u64);
|
||||
pub struct Bitboard(pub u64);
|
||||
|
||||
impl Bitboard {
|
||||
#[inline]
|
||||
pub fn new() -> Self {
|
||||
pub const fn new() -> Self {
|
||||
Self(0)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_empty(&self) -> bool {
|
||||
pub const fn is_empty(&self) -> bool {
|
||||
self.0 == 0
|
||||
}
|
||||
|
||||
|
|
@ -38,7 +41,7 @@ impl Bitboard {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn pop(&mut self) -> Option<Square> {
|
||||
pub const fn pop(&mut self) -> Option<Square> {
|
||||
let Self(ref mut mask) = self;
|
||||
let square = match mask {
|
||||
0 => None,
|
||||
|
|
@ -54,7 +57,23 @@ impl Bitboard {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn trans(&self, direction: Direction) -> Self {
|
||||
pub const fn contains(&self, square: Square) -> bool {
|
||||
self.0 & (1 << square as u8) != 0
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub const fn remove(&mut self, square: Square) {
|
||||
self.0 &= !(1 << square as u8);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub const fn mirror(self) -> Bitboard {
|
||||
let [a, b, c, d, e, f, g, h] = self.0.to_le_bytes();
|
||||
Self(u64::from_le_bytes([h, g, f, e, d, c, b, a]))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn trans(&self, direction: Direction) -> Self {
|
||||
match direction {
|
||||
Direction::North => Self(self.0 << 8),
|
||||
Direction::NorthEast => Self(self.0 << 9) & !File::A.bitboard(),
|
||||
|
|
@ -66,17 +85,6 @@ impl Bitboard {
|
|||
Direction::NorthWest => Self(self.0 << 7) & !File::H.bitboard(),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub const fn contains(&self, square: Square) -> bool {
|
||||
self.0 & (1 << square as u8) != 0
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn mirror(self) -> Bitboard {
|
||||
let [a, b, c, d, e, f, g, h] = self.0.to_le_bytes();
|
||||
Self(u64::from_le_bytes([h, g, f, e, d, c, b, a]))
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::BitOr for Bitboard {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue