diff --git a/bitboard/src/bitboard.rs b/bitboard/src/bitboard.rs index 215e917..3787bb8 100644 --- a/bitboard/src/bitboard.rs +++ b/bitboard/src/bitboard.rs @@ -25,7 +25,7 @@ impl BitBoard { #[must_use] pub const fn empty() -> BitBoard { - BitBoard(0) + Self::EMPTY } #[must_use] @@ -79,8 +79,8 @@ impl BitBoard { impl BitBoard { #[must_use] - pub const fn as_bits(&self) -> &u64 { - &self.0 + pub const fn as_bits(&self) -> u64 { + self.0 } /// Returns `true` if the [`BitBoard`] has no bits set. @@ -113,7 +113,7 @@ impl BitBoard { } /// Returns `true` if this [`BitBoard`] has the bit corresponding to `square` set. - pub fn is_set(self, square: Square) -> bool { + pub fn contains(self, square: Square) -> bool { let square_bitboard: BitBoard = square.into(); !(self & square_bitboard).is_empty() } @@ -132,14 +132,14 @@ impl BitBoard { self.0.count_ones() } - pub fn set_square(&mut self, sq: Square) { - let sq_bb: BitBoard = sq.into(); - *self |= sq_bb + pub fn set(&mut self, square: Square) { + let square_bitboard: BitBoard = square.into(); + self.0 |= square_bitboard.0 } - pub fn clear_square(&mut self, sq: Square) { - let sq_bb: BitBoard = sq.into(); - *self &= !sq_bb + pub fn clear(&mut self, square: Square) { + let square_bitboard: BitBoard = square.into(); + self.0 &= !square_bitboard.0 } /// Returns `true` if this BitBoard represents a single square. @@ -202,6 +202,12 @@ impl Default for BitBoard { } } +impl From for u64 { + fn from(value: BitBoard) -> Self { + value.as_bits() + } +} + impl From for BitBoard { fn from(value: File) -> Self { library::FILES[*value.as_index() as usize] @@ -228,13 +234,10 @@ impl From for BitBoard { impl FromIterator for BitBoard { fn from_iter>(iter: T) -> Self { - let mut builder = BitBoardBuilder::empty(); - - for sq in iter { - builder = builder.square(sq) - } - - builder.build() + iter.into_iter().fold(BitBoard::EMPTY, |mut acc, sq| { + acc.set(sq); + acc + }) } }