move get_index to misc.rs
This commit is contained in:
parent
7c4f05af3e
commit
c8ac4ce84b
@ -1,4 +1,4 @@
|
|||||||
use super::board::Board;
|
use super::{board::Board, misc::get_index};
|
||||||
use const_fn::const_fn;
|
use const_fn::const_fn;
|
||||||
use static_assertions::const_assert;
|
use static_assertions::const_assert;
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ impl BitBoard {
|
|||||||
|
|
||||||
#[const_fn(cfg(not(feature = "bitvec")))]
|
#[const_fn(cfg(not(feature = "bitvec")))]
|
||||||
pub const fn get(&self, row: usize, col: usize) -> bool {
|
pub const fn get(&self, row: usize, col: usize) -> bool {
|
||||||
self.get_by_index(Self::get_index(row, col))
|
self.get_by_index(get_index(row, col))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "bitvec"))]
|
#[cfg(not(feature = "bitvec"))]
|
||||||
@ -51,7 +51,7 @@ impl BitBoard {
|
|||||||
|
|
||||||
#[const_fn(cfg(not(feature = "bitvec")))]
|
#[const_fn(cfg(not(feature = "bitvec")))]
|
||||||
pub const fn set(&mut self, row: usize, col: usize, value: bool) {
|
pub const fn set(&mut self, row: usize, col: usize, value: bool) {
|
||||||
self.set_by_index(Self::get_index(row, col), value);
|
self.set_by_index(get_index(row, col), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "bitvec"))]
|
#[cfg(not(feature = "bitvec"))]
|
||||||
@ -61,10 +61,6 @@ impl BitBoard {
|
|||||||
self.0 |= (value as BitBoardInner) << index; // set bit (if needed)
|
self.0 |= (value as BitBoardInner) << index; // set bit (if needed)
|
||||||
}
|
}
|
||||||
|
|
||||||
const fn get_index(row: usize, col: usize) -> usize {
|
|
||||||
row * Board::BOARD_SIZE + col
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "bitvec")]
|
#[cfg(feature = "bitvec")]
|
||||||
pub fn get_by_index(&self, index: usize) -> bool {
|
pub fn get_by_index(&self, index: usize) -> bool {
|
||||||
self.0[index]
|
self.0[index]
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
use super::{
|
use super::{
|
||||||
bitboard::BitBoard,
|
bitboard::BitBoard,
|
||||||
|
misc::get_index,
|
||||||
misc::{diag_raw, split_from},
|
misc::{diag_raw, split_from},
|
||||||
piece::Piece,
|
piece::Piece,
|
||||||
};
|
};
|
||||||
@ -20,10 +21,6 @@ type ChainCollection = ArrayVec<Chain, 8>;
|
|||||||
pub struct PosMap<T: Default>(ArrayVec<T, { Board::BOARD_AREA }>);
|
pub struct PosMap<T: Default>(ArrayVec<T, { Board::BOARD_AREA }>);
|
||||||
|
|
||||||
impl<T: Default> PosMap<T> {
|
impl<T: Default> PosMap<T> {
|
||||||
const fn index(row: usize, col: usize) -> usize {
|
|
||||||
row * Board::BOARD_SIZE + col
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(clippy::new_without_default)]
|
#[allow(clippy::new_without_default)]
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self(ArrayVec::from_iter(
|
Self(ArrayVec::from_iter(
|
||||||
@ -32,7 +29,7 @@ impl<T: Default> PosMap<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(&self, row: usize, col: usize) -> &T {
|
pub fn get(&self, row: usize, col: usize) -> &T {
|
||||||
let index = Self::index(row, col);
|
let index = get_index(row, col);
|
||||||
|
|
||||||
debug_assert!(
|
debug_assert!(
|
||||||
Board::BOARD_AREA + 1 >= index,
|
Board::BOARD_AREA + 1 >= index,
|
||||||
@ -44,7 +41,7 @@ impl<T: Default> PosMap<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn set(&mut self, row: usize, col: usize, value: T) {
|
pub fn set(&mut self, row: usize, col: usize, value: T) {
|
||||||
let index = Self::index(row, col);
|
let index = get_index(row, col);
|
||||||
debug_assert!(
|
debug_assert!(
|
||||||
Board::BOARD_AREA + 1 >= index,
|
Board::BOARD_AREA + 1 >= index,
|
||||||
"index out of range, was: {}",
|
"index out of range, was: {}",
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
use super::Board;
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use std::{iter::Rev, ops::RangeInclusive};
|
use std::{iter::Rev, ops::RangeInclusive};
|
||||||
|
|
||||||
@ -38,6 +39,11 @@ where
|
|||||||
[(0, 0), (1, 1), (1, 0), (0, 1)].map(move |(a, b)| i_chains[a].clone().zip(j_chains[b].clone()))
|
[(0, 0), (1, 1), (1, 0), (0, 1)].map(move |(a, b)| i_chains[a].clone().zip(j_chains[b].clone()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Convert a row and column to an index in the board
|
||||||
|
pub const fn get_index(row: usize, col: usize) -> usize {
|
||||||
|
row * Board::BOARD_SIZE + col
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user