[bitboard] Remove #[must_use] from method calls; add it to BitBoard type
This commit is contained in:
parent
f1431ea4e9
commit
184e81a7c8
1 changed files with 5 additions and 11 deletions
|
@ -30,12 +30,12 @@ const SQUARES_NUM: u8 = Square::NUM as u8;
|
||||||
/// A B C D E F G H
|
/// A B C D E F G H
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
|
#[must_use]
|
||||||
#[derive(Clone, Copy, Eq, Hash, PartialEq)]
|
#[derive(Clone, Copy, Eq, Hash, PartialEq)]
|
||||||
pub struct BitBoard(pub(crate) u64);
|
pub struct BitBoard(pub(crate) u64);
|
||||||
|
|
||||||
macro_rules! moves_getter {
|
macro_rules! moves_getter {
|
||||||
($getter_name:ident) => {
|
($getter_name:ident) => {
|
||||||
#[must_use]
|
|
||||||
pub fn $getter_name(sq: Square) -> BitBoard {
|
pub fn $getter_name(sq: Square) -> BitBoard {
|
||||||
library::library().$getter_name(sq)
|
library::library().$getter_name(sq)
|
||||||
}
|
}
|
||||||
|
@ -46,44 +46,38 @@ impl BitBoard {
|
||||||
const EMPTY: BitBoard = BitBoard(u64::MIN);
|
const EMPTY: BitBoard = BitBoard(u64::MIN);
|
||||||
const FULL: BitBoard = BitBoard(u64::MAX);
|
const FULL: BitBoard = BitBoard(u64::MAX);
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub const fn empty() -> BitBoard {
|
pub const fn empty() -> BitBoard {
|
||||||
Self::EMPTY
|
Self::EMPTY
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub const fn full() -> BitBoard {
|
pub const fn full() -> BitBoard {
|
||||||
Self::FULL
|
Self::FULL
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub const fn new(bits: u64) -> BitBoard {
|
pub const fn new(bits: u64) -> BitBoard {
|
||||||
BitBoard(bits)
|
BitBoard(bits)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
// TODO: Is &u8 really necessary here?
|
||||||
pub fn rank(rank: &u8) -> BitBoard {
|
pub fn rank(rank: &u8) -> BitBoard {
|
||||||
debug_assert!(*rank < 8);
|
debug_assert!(*rank < 8);
|
||||||
library::RANKS[*rank as usize]
|
library::RANKS[*rank as usize]
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
// TODO: Is &u8 really necessary here?
|
||||||
pub fn file(file: &u8) -> BitBoard {
|
pub fn file(file: &u8) -> BitBoard {
|
||||||
debug_assert!(*file < 8);
|
debug_assert!(*file < 8);
|
||||||
library::FILES[*file as usize]
|
library::FILES[*file as usize]
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn ray(sq: Square, dir: Direction) -> BitBoard {
|
pub fn ray(sq: Square, dir: Direction) -> BitBoard {
|
||||||
library::library().ray(sq, dir)
|
library::library().ray(sq, dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn pawn_attacks(sq: Square, color: Color) -> BitBoard {
|
pub fn pawn_attacks(sq: Square, color: Color) -> BitBoard {
|
||||||
library::library().pawn_attacks(sq, color)
|
library::library().pawn_attacks(sq, color)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn pawn_pushes(sq: Square, color: Color) -> BitBoard {
|
pub fn pawn_pushes(sq: Square, color: Color) -> BitBoard {
|
||||||
library::library().pawn_pushes(sq, color)
|
library::library().pawn_pushes(sq, color)
|
||||||
}
|
}
|
||||||
|
@ -94,12 +88,10 @@ impl BitBoard {
|
||||||
moves_getter!(queen_moves);
|
moves_getter!(queen_moves);
|
||||||
moves_getter!(king_moves);
|
moves_getter!(king_moves);
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub const fn kingside(color: Color) -> &'static BitBoard {
|
pub const fn kingside(color: Color) -> &'static BitBoard {
|
||||||
&library::KINGSIDES[color as usize]
|
&library::KINGSIDES[color as usize]
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub const fn queenside(color: Color) -> &'static BitBoard {
|
pub const fn queenside(color: Color) -> &'static BitBoard {
|
||||||
&library::QUEENSIDES[color as usize]
|
&library::QUEENSIDES[color as usize]
|
||||||
}
|
}
|
||||||
|
@ -243,10 +235,12 @@ impl BitBoard {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub fn occupied_squares_leading(&self) -> LeadingBitScanner {
|
pub fn occupied_squares_leading(&self) -> LeadingBitScanner {
|
||||||
LeadingBitScanner::new(self.0)
|
LeadingBitScanner::new(self.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub fn occupied_squares_trailing(&self) -> TrailingBitScanner {
|
pub fn occupied_squares_trailing(&self) -> TrailingBitScanner {
|
||||||
TrailingBitScanner::new(self.0)
|
TrailingBitScanner::new(self.0)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue