[board] Clean up Display and Debug implementations on BitBoard, Flags, Position, and PlacedPiece
This commit is contained in:
parent
2269df2ed9
commit
c413db0bf1
4 changed files with 16 additions and 29 deletions
|
@ -145,9 +145,7 @@ impl fmt::Display for BitBoard {
|
|||
|
||||
impl fmt::Debug for BitBoard {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
||||
f.debug_tuple("BitBoard")
|
||||
.field(&format_args!("{:064b}", self.0))
|
||||
.finish()
|
||||
write!(f, "BitBoard({:064b})", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -240,6 +240,12 @@ impl PlacedPiece {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for PlacedPiece {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}{}", self.piece, self.square)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
|
@ -2,8 +2,9 @@
|
|||
|
||||
use super::position::BoardSide;
|
||||
use crate::piece::Color;
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||
#[derive(Clone, Copy, Eq, Hash, PartialEq)]
|
||||
pub(super) struct Flags(u8);
|
||||
|
||||
impl Flags {
|
||||
|
@ -25,6 +26,12 @@ impl Flags {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for Flags {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "Flags({:08b})", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Flags {
|
||||
fn default() -> Self {
|
||||
Flags(0b00001111)
|
||||
|
|
|
@ -8,7 +8,6 @@ use crate::{
|
|||
BitBoard, Square,
|
||||
};
|
||||
use std::cell::OnceCell;
|
||||
use std::fmt;
|
||||
|
||||
/// A lateral side of the board relative to the player. Kingside is the side the
|
||||
/// player's king starts on. Queenside is the side of the board the player's
|
||||
|
@ -18,7 +17,7 @@ pub(crate) enum BoardSide {
|
|||
Queen,
|
||||
}
|
||||
|
||||
#[derive(Clone, Eq, PartialEq)]
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct Position {
|
||||
color_to_move: Color,
|
||||
flags: Flags,
|
||||
|
@ -238,29 +237,6 @@ impl FromIterator<PlacedPiece> for Position {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for Position {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "Position {{\n")?;
|
||||
write!(f, " color_to_move: {:?},\n", self.color_to_move)?;
|
||||
|
||||
write!(f, " pieces_per_color: [\n")?;
|
||||
for bb in self.pieces_per_color {
|
||||
write!(f, " {bb:?},\n")?;
|
||||
}
|
||||
write!(f, " ],\n")?;
|
||||
|
||||
write!(f, " pieces_per_type: [\n")?;
|
||||
for color_bbs in self.pieces_per_type {
|
||||
write!(f, " [\n")?;
|
||||
for bb in color_bbs {
|
||||
write!(f, " {bb:?},\n")?;
|
||||
}
|
||||
write!(f, " ],\n")?;
|
||||
}
|
||||
write!(f, " ],\n}}")
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue