place weighting

This commit is contained in:
2025-02-20 19:14:31 -05:00
parent e1d83825b7
commit d29095bc9d
8 changed files with 101 additions and 51 deletions

View File

@@ -1,4 +1,4 @@
use crate::repr::board::{BOARD_AREA, BOARD_SIZE};
use crate::repr::board::Board;
use const_fn::const_fn;
use static_assertions::const_assert;
@@ -15,7 +15,7 @@ use bitvec::prelude::*;
type BBBaseType = u64;
#[cfg(feature = "bitvec")]
pub type BitBoardInner = BitArr!(for BOARD_AREA, in BBBaseType, Lsb0);
pub type BitBoardInner = BitArr!(for Board::BOARD_AREA, in BBBaseType, Lsb0);
#[cfg(not(feature = "bitvec"))]
pub type BitBoardInner = u64;
@@ -24,7 +24,7 @@ pub type BitBoardInner = u64;
pub struct BitBoard(BitBoardInner);
// BitBoard should be big enough to fit all points on the board
const_assert!(std::mem::size_of::<BitBoard>() * 8 >= BOARD_AREA);
const_assert!(std::mem::size_of::<BitBoard>() * 8 >= Board::BOARD_AREA);
impl Default for BitBoard {
fn default() -> Self {
@@ -35,7 +35,7 @@ impl Default for BitBoard {
impl BitBoard {
#[cfg(feature = "bitvec")]
pub const fn new() -> Self {
Self(bitarr!(BBBaseType, Lsb0; 0; BOARD_AREA))
Self(bitarr!(BBBaseType, Lsb0; 0; Board::BOARD_AREA))
}
#[cfg(not(feature = "bitvec"))]
@@ -57,7 +57,7 @@ impl BitBoard {
}
const fn get_index(row: usize, col: usize) -> usize {
row * BOARD_SIZE + col
row * Board::BOARD_SIZE + col
}
#[cfg(feature = "bitvec")]
@@ -84,8 +84,8 @@ mod test {
#[test]
fn set_and_get() {
let mut b = BitBoard::new();
for i in 0..BOARD_SIZE {
for j in 0..BOARD_SIZE {
for i in 0..Board::BOARD_SIZE {
for j in 0..Board::BOARD_SIZE {
assert!(
!b.get(i, j),
"A just-initalized BitBoard should be completely empty"