[bitboard,core,position] Address a bunch of clippy warnings

This commit is contained in:
Eryn Wells 2024-03-14 17:00:46 -07:00
parent d0abbd8f93
commit 27a36565f3
8 changed files with 63 additions and 32 deletions

View file

@ -89,7 +89,7 @@ mod tests {
#[test]
fn leading_complex() {
let mut scanner = LeadingBitScanner::new(0b11000101);
let mut scanner = LeadingBitScanner::new(0b_1100_0101);
assert_eq!(scanner.next(), Some(7));
assert_eq!(scanner.next(), Some(6));
assert_eq!(scanner.next(), Some(2));
@ -112,7 +112,7 @@ mod tests {
#[test]
fn trailing_complex() {
let mut scanner = TrailingBitScanner::new(0b11000101);
let mut scanner = TrailingBitScanner::new(0b_1100_0101);
assert_eq!(scanner.next(), Some(0));
assert_eq!(scanner.next(), Some(2));
assert_eq!(scanner.next(), Some(6));

View file

@ -146,18 +146,23 @@ impl BitBoard {
}
impl BitBoard {
/// Return an Iterator over the occupied squares, starting from the leading
/// (most-significant bit) end of the field.
/// Returns an Iterator over the occupied squares.
///
/// The Iterator yields squares starting from the leading (most-significant bit) end of the
/// board to the trailing (least-significant bit) end.
#[must_use]
pub fn occupied_squares(&self) -> impl Iterator<Item = Square> {
LeadingBitScanner::new(self.0).map(|idx| unsafe { Square::from_index(idx as u8) })
}
/// Return an Iterator over the occupied squares, starting from the trailing
/// (least-significant bit) end of the field.
#[must_use]
pub fn occupied_squares_trailing(&self) -> impl Iterator<Item = Square> {
TrailingBitScanner::new(self.0).map(|idx| unsafe { Square::from_index(idx as u8) })
}
#[must_use]
pub fn first_occupied_square(&self) -> Option<Square> {
let leading_zeros = self.0.leading_zeros() as u8;
if leading_zeros < Square::NUM as u8 {
@ -167,6 +172,7 @@ impl BitBoard {
}
}
#[must_use]
pub fn first_occupied_square_trailing(&self) -> Option<Square> {
let trailing_zeros = self.0.trailing_zeros() as u8;
if trailing_zeros < Square::NUM as u8 {

View file

@ -12,17 +12,21 @@ use crate::BitBoard;
use chessfriend_core::{Color, Direction, Square};
use std::sync::OnceLock;
#[allow(clippy::identity_op)]
#[allow(clippy::erasing_op)]
pub(crate) const RANKS: [BitBoard; 8] = [
BitBoard(0xFF << 0 * 8),
BitBoard(0xFF << 1 * 8),
BitBoard(0xFF << 2 * 8),
BitBoard(0xFF << 3 * 8),
BitBoard(0xFF << 4 * 8),
BitBoard(0xFF << 5 * 8),
BitBoard(0xFF << 6 * 8),
BitBoard(0xFF << 7 * 8),
BitBoard(0xFF << (0 * 8)),
BitBoard(0xFF << (1 * 8)),
BitBoard(0xFF << (2 * 8)),
BitBoard(0xFF << (3 * 8)),
BitBoard(0xFF << (4 * 8)),
BitBoard(0xFF << (5 * 8)),
BitBoard(0xFF << (6 * 8)),
BitBoard(0xFF << (7 * 8)),
];
#[allow(clippy::identity_op)]
#[allow(clippy::erasing_op)]
pub(crate) const FILES: [BitBoard; 8] = [
BitBoard(0x0101010101010101 << 0),
BitBoard(0x0101010101010101 << 1),