diff --git a/board/src/bitboard/bitboard.rs b/board/src/bitboard/bitboard.rs index 926e35a..7d96274 100644 --- a/board/src/bitboard/bitboard.rs +++ b/board/src/bitboard/bitboard.rs @@ -17,6 +17,10 @@ impl BitBoard { BitBoard(bits) } + pub fn rank(rank: u8) -> BitBoard { + BitBoard(0xFF).shift_north(rank) + } + pub fn is_empty(&self) -> bool { self.0 == 0 } @@ -38,6 +42,11 @@ impl BitBoard { const NOT_A_FILE: u64 = 0xfefefefefefefefe; const NOT_H_FILE: u64 = 0x7f7f7f7f7f7f7f7f; + #[inline] + pub fn shift_north(&self, n: u8) -> BitBoard { + BitBoard(self.0 << (8 * n)) + } + #[inline] pub fn shift_north_one(&self) -> BitBoard { BitBoard(self.0 << 8) @@ -139,6 +148,18 @@ mod tests { use super::*; use crate::Square; + #[test] + fn rank() { + assert_eq!(BitBoard::rank(0).0, 0xFF, "Rank 1"); + assert_eq!(BitBoard::rank(1).0, 0xFF00, "Rank 2"); + assert_eq!(BitBoard::rank(2).0, 0xFF0000, "Rank 3"); + assert_eq!(BitBoard::rank(3).0, 0xFF000000, "Rank 4"); + assert_eq!(BitBoard::rank(4).0, 0xFF00000000, "Rank 5"); + assert_eq!(BitBoard::rank(5).0, 0xFF0000000000, "Rank 6"); + assert_eq!(BitBoard::rank(6).0, 0xFF000000000000, "Rank 7"); + assert_eq!(BitBoard::rank(7).0, 0xFF00000000000000, "Rank 8"); + } + #[test] fn is_empty() { assert!(BitBoard(0).is_empty()); @@ -210,6 +231,14 @@ mod tests { ); } + #[test] + fn shift_n() { + assert_eq!( + BitBoard(0x0008_0000_0000).shift_north(2), + BitBoard(0x0008_0000_0000_0000) + ); + } + #[test] fn pieces() { let bb = BitBoard(0x1001_1010); // e4