[board] Implement BitAnd and BitOr on BitBoard and make it's u64 private

This commit is contained in:
Eryn Wells 2023-12-22 08:50:03 -08:00
parent aa7e901241
commit 6af64171a2
2 changed files with 69 additions and 28 deletions

View file

@ -2,11 +2,20 @@
use crate::square::Square;
use std::arch::asm;
use std::ops::{BitAnd, BitOr};
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct BitBoard(pub u64);
pub struct BitBoard(u64);
impl BitBoard {
pub fn empty() -> BitBoard {
BitBoard(0)
}
pub fn from_bit_field(bits: u64) -> BitBoard {
BitBoard(bits)
}
fn is_empty(&self) -> bool {
self.0 == 0
}
@ -38,6 +47,38 @@ impl BitBoard {
}
}
impl BitAnd for BitBoard {
type Output = BitBoard;
fn bitand(self, rhs: Self) -> Self {
BitBoard(self.0 & rhs.0)
}
}
impl BitAnd<&BitBoard> for BitBoard {
type Output = BitBoard;
fn bitand(self, rhs: &Self) -> Self {
BitBoard(self.0 & rhs.0)
}
}
impl BitOr for BitBoard {
type Output = BitBoard;
fn bitor(self, rhs: Self) -> Self {
BitBoard(self.0 | rhs.0)
}
}
impl BitOr<&BitBoard> for BitBoard {
type Output = BitBoard;
fn bitor(self, rhs: &Self) -> Self {
BitBoard(self.0 | rhs.0)
}
}
#[cfg(test)]
mod tests {
use super::*;