rename board variables

This commit is contained in:
2025-03-11 17:05:40 -04:00
parent f84706ac40
commit 37292dd0f1
3 changed files with 24 additions and 24 deletions

View File

@@ -10,13 +10,13 @@ use std::{
/// Map of all points on the board against some type T
/// Used to index like so: example[i][j]
/// with each coordinate
pub struct PosMap<T: Default>(ArrayVec<T, { Board::BOARD_AREA.0 as usize }>);
pub struct PosMap<T: Default>(ArrayVec<T, { Board::AREA.0 as usize }>);
impl<T: Default> PosMap<T> {
#[allow(clippy::new_without_default)]
pub fn new() -> Self {
Self(ArrayVec::from_iter(
(0..Board::BOARD_AREA.0).map(|_| Default::default()),
(0..Board::AREA.0).map(|_| Default::default()),
))
}
@@ -29,13 +29,13 @@ impl<T: Default> PosMap<T> {
}
}
type PosMapOrig<T> = [[T; Board::BOARD_SIZE as usize]; Board::BOARD_SIZE as usize];
type PosMapOrig<T> = [[T; Board::SIZE as usize]; Board::SIZE as usize];
impl<T: Default + Copy> From<PosMapOrig<T>> for PosMap<T> {
fn from(value: PosMapOrig<T>) -> Self {
let mut new = Self::new();
for i in 0..Board::BOARD_SIZE {
for j in 0..Board::BOARD_SIZE {
for i in 0..Board::SIZE {
for j in 0..Board::SIZE {
new.set((i, j).into(), value[i as usize][j as usize]);
}
}
@@ -97,25 +97,25 @@ pub struct Board {
impl fmt::Display for Board {
#[allow(clippy::repeat_once)] // clippy gets mad about when PADDING == 1
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let horiz_sep_line = "-".repeat((Self::BOARD_SIZE * 2 + 1) as usize);
let horiz_sep_line = "-".repeat((Self::SIZE * 2 + 1) as usize);
// basically calculates the # of digits BOARD_SIZE needs
const PADDING: usize = (Board::BOARD_SIZE - 1).ilog10() as usize + 1;
const PADDING: usize = (Board::SIZE - 1).ilog10() as usize + 1;
let space_padding = " ".repeat(PADDING);
// Print numbers at top so the board can be read more easier
write!(f, "{} ", space_padding)?;
for j in (0..Self::BOARD_SIZE).rev() {
for j in (0..Self::SIZE).rev() {
write!(f, "{:0PADDING$} ", j)?;
}
writeln!(f)?;
for i in (0..Self::BOARD_SIZE).rev() {
for i in (0..Self::SIZE).rev() {
writeln!(f, "{}{}", space_padding, horiz_sep_line)?;
write!(f, "{:0PADDING$}|", i)?;
for j in (0..Self::BOARD_SIZE).rev() {
for j in (0..Self::SIZE).rev() {
write!(
f,
"{}|",
@@ -152,10 +152,10 @@ impl fmt::Debug for Board {
impl Board {
/// Width of the board
pub const BOARD_SIZE: CoordAxis = 8;
pub const SIZE: CoordAxis = 8;
/// Area of the board
pub const BOARD_AREA: CoordPair = CoordPair::area(Self::BOARD_SIZE);
pub const AREA: CoordPair = CoordPair::area(Self::SIZE);
/// Create a new empty board
#[allow(clippy::new_without_default)]
@@ -183,7 +183,7 @@ impl Board {
/// Starting position
pub const fn starting_pos(mut self) -> Self {
let hf = Self::BOARD_SIZE / 2;
let hf = Self::SIZE / 2;
self.place_unchecked(CoordPair::from_axes(hf - 1, hf - 1), Piece::White);
self.place_unchecked(CoordPair::from_axes(hf, hf - 1), Piece::Black);
@@ -194,7 +194,7 @@ impl Board {
/// Provides an iterator of all possible positions on the board
pub fn all_positions() -> impl Iterator<Item = CoordPair> {
(0..Self::BOARD_AREA.0).map(CoordPair)
(0..Self::AREA.0).map(CoordPair)
}
/// Returns an iterator of all possible moves a `color` can make