const nits
This commit is contained in:
parent
2ef316ab52
commit
876d829e5e
@ -16,8 +16,6 @@ path = "src/main.rs"
|
||||
# increases perf at the cost of compile-time
|
||||
codegen-units = 1 # ~4-5% perf bump
|
||||
lto = true
|
||||
# incremental = false
|
||||
# overflow-checks = false
|
||||
|
||||
[profile.profile]
|
||||
inherits = "release"
|
||||
|
||||
@ -63,6 +63,8 @@ impl BitBoard {
|
||||
self.0 &= !(1 << index)
|
||||
}
|
||||
|
||||
// PERF! was going to optimize setting multiple indexes,
|
||||
// seems rust does this for us: https://godbolt.org/z/ddj3dMxsP
|
||||
#[cfg(not(feature = "bitvec"))]
|
||||
const fn set_bit(&mut self, index: usize) {
|
||||
self.0 |= 1 << index
|
||||
@ -84,7 +86,7 @@ impl BitBoard {
|
||||
|
||||
// works on both `bitvec` and native (const on native)
|
||||
#[const_fn(cfg(not(feature = "bitvec")))]
|
||||
pub fn count(&self) -> usize {
|
||||
pub const fn count(&self) -> usize {
|
||||
self.0.count_ones() as usize
|
||||
}
|
||||
}
|
||||
|
||||
15
src/board.rs
15
src/board.rs
@ -63,6 +63,8 @@ fn gen_adj_lookup() -> PosMap<ChainCollection> {
|
||||
"chains go out-of-bounds"
|
||||
);
|
||||
|
||||
// ensure all nodes in all chains are unique across chains, ensures beavior in
|
||||
// [`Board::propegate_from`]
|
||||
let mut uniq = HashSet::new();
|
||||
assert!(
|
||||
chains.iter().flatten().all(move |x| uniq.insert(x)),
|
||||
@ -164,7 +166,8 @@ impl Board {
|
||||
}
|
||||
|
||||
/// Starting position
|
||||
pub fn starting_pos(mut self) -> Self {
|
||||
#[const_fn(cfg(not(feature = "bitvec")))]
|
||||
pub const fn starting_pos(mut self) -> Self {
|
||||
self.place_unchecked((BOARD_SIZE / 2) - 1, (BOARD_SIZE / 2) - 1, Piece::White);
|
||||
self.place_unchecked(BOARD_SIZE / 2, (BOARD_SIZE / 2) - 1, Piece::Black);
|
||||
self.place_unchecked((BOARD_SIZE / 2) - 1, BOARD_SIZE / 2, Piece::Black);
|
||||
@ -205,7 +208,7 @@ impl Board {
|
||||
|
||||
/// Returns the color of a place on the [`Board`] at a position
|
||||
#[const_fn(cfg(not(feature = "bitvec")))]
|
||||
pub fn get(&self, i: usize, j: usize) -> Option<Piece> {
|
||||
pub const fn get(&self, i: usize, j: usize) -> Option<Piece> {
|
||||
if self.get_piece(i, j, Piece::White) {
|
||||
Some(Piece::White)
|
||||
} else if self.get_piece(i, j, Piece::Black) {
|
||||
@ -217,13 +220,13 @@ impl Board {
|
||||
|
||||
/// Place a piece without checking for propegation of validity
|
||||
#[const_fn(cfg(not(feature = "bitvec")))]
|
||||
fn place_unchecked(&mut self, i: usize, j: usize, piece: Piece) {
|
||||
const fn place_unchecked(&mut self, i: usize, j: usize, piece: Piece) {
|
||||
self.board_mut(piece).set(i, j, true);
|
||||
self.board_mut(piece.flip()).set(i, j, false);
|
||||
}
|
||||
|
||||
#[const_fn(cfg(not(feature = "bitvec")))]
|
||||
fn delete(&mut self, i: usize, j: usize) {
|
||||
const fn delete(&mut self, i: usize, j: usize) {
|
||||
self.board_mut(Piece::White).set(i, j, false);
|
||||
self.board_mut(Piece::Black).set(i, j, false);
|
||||
}
|
||||
@ -312,14 +315,14 @@ impl Board {
|
||||
|
||||
/// Count the number of a type of [`Piece`] on the board
|
||||
#[const_fn(cfg(not(feature = "bitvec")))]
|
||||
pub fn count(&self, piece: Piece) -> usize {
|
||||
pub const fn count(&self, piece: Piece) -> usize {
|
||||
self.board(piece).count()
|
||||
}
|
||||
|
||||
/// Get the "net score" of a player
|
||||
/// Formula: `net_score = Score_player - Score_opponent`
|
||||
#[const_fn(cfg(not(feature = "bitvec")))]
|
||||
pub fn net_score(&self, piece: Piece) -> isize {
|
||||
pub const fn net_score(&self, piece: Piece) -> isize {
|
||||
self.count(piece) as isize - self.count(piece.flip()) as isize
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user