[board] Implement a BitBoard MoveLibrary
This struct computes and stores piece moves per square to speed up computation of move lists. Initialize a `static mut` instance once via std::sync::Once, and return a static reference to it. So far, it computes king and knight moves. Make BitBoard::empty() and MoveLibrary::new() const functions, enabling static construction of the MOVE_LIBRARY instance without needing to wrap it in an Option.
This commit is contained in:
parent
4a54d8b877
commit
06bfc4ac57
2 changed files with 93 additions and 2 deletions
|
@ -1,6 +1,6 @@
|
|||
// Eryn Wells <eryn@erynwells.me>
|
||||
|
||||
use super::library::{FILES, RANKS};
|
||||
use super::library::{library, FILES, RANKS};
|
||||
use super::BitScanner;
|
||||
use crate::Square;
|
||||
use std::fmt;
|
||||
|
@ -10,7 +10,7 @@ use std::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, Not};
|
|||
pub(crate) struct BitBoard(pub(super) u64);
|
||||
|
||||
impl BitBoard {
|
||||
pub fn empty() -> BitBoard {
|
||||
pub const fn empty() -> BitBoard {
|
||||
BitBoard(0)
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,10 @@ impl BitBoard {
|
|||
FILES[file]
|
||||
}
|
||||
|
||||
pub fn knight_moves(sq: Square) -> BitBoard {
|
||||
library().knight_moves(sq)
|
||||
}
|
||||
|
||||
pub fn from_square(sq: Square) -> BitBoard {
|
||||
BitBoard(1 << sq.index())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue