[board] Return copies of rank and file bitboards from static lists
This commit is contained in:
parent
e30bcb3105
commit
1cc8b4520f
3 changed files with 31 additions and 4 deletions
|
@ -1,5 +1,6 @@
|
|||
// Eryn Wells <eryn@erynwells.me>
|
||||
|
||||
use super::library::{FILES, RANKS};
|
||||
use super::BitScanner;
|
||||
use crate::Square;
|
||||
use std::fmt;
|
||||
|
@ -17,14 +18,14 @@ impl BitBoard {
|
|||
BitBoard(bits)
|
||||
}
|
||||
|
||||
pub fn rank(rank: u8) -> BitBoard {
|
||||
pub fn rank(rank: usize) -> BitBoard {
|
||||
assert!(rank < 8);
|
||||
BitBoard(0xFF).shift_north(rank)
|
||||
RANKS[rank]
|
||||
}
|
||||
|
||||
pub fn file(file: u8) -> BitBoard {
|
||||
pub fn file(file: usize) -> BitBoard {
|
||||
assert!(file < 8);
|
||||
BitBoard(0x0101010101010101).shift_east(file)
|
||||
FILES[file]
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
|
|
25
board/src/bitboard/library.rs
Normal file
25
board/src/bitboard/library.rs
Normal file
|
@ -0,0 +1,25 @@
|
|||
// Eryn Wells <eryn@erynwells.me>
|
||||
|
||||
use super::BitBoard;
|
||||
|
||||
pub(super) 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),
|
||||
];
|
||||
|
||||
pub(super) const FILES: [BitBoard; 8] = [
|
||||
BitBoard(0x0101010101010101 << 0),
|
||||
BitBoard(0x0101010101010101 << 1),
|
||||
BitBoard(0x0101010101010101 << 2),
|
||||
BitBoard(0x0101010101010101 << 3),
|
||||
BitBoard(0x0101010101010101 << 4),
|
||||
BitBoard(0x0101010101010101 << 5),
|
||||
BitBoard(0x0101010101010101 << 6),
|
||||
BitBoard(0x0101010101010101 << 7),
|
||||
];
|
|
@ -1,5 +1,6 @@
|
|||
mod bit_scanner;
|
||||
mod bitboard;
|
||||
mod library;
|
||||
mod shifts;
|
||||
|
||||
pub(crate) use self::bit_scanner::BitScanner;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue