[board] Implement a DiagramFormatter that writes a graphical diagram of a Position

Remove fmt::Display from Position and move display to a DiagramFormatter type that implements that trait and writes a position to a formatter.
This commit is contained in:
Eryn Wells 2023-12-26 21:37:22 -07:00
parent 8d06cbf0f8
commit 19c48b9816
3 changed files with 63 additions and 25 deletions

View file

@ -144,31 +144,6 @@ impl fmt::Debug for Position {
}
}
impl fmt::Display for Position {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut output = String::new();
output.push_str(" +-----------------+\n");
for rank in (0..8).rev() {
output.push_str("{rank} | ");
for file in 0..8 {
let square = Square::from_rank_file(rank, file);
// TODO: Get piece at square
output.push_str(". ");
}
output.push_str("|\n");
}
output.push_str(" +-----------------+\n");
output.push_str(" a b c d e f g h\n");
write!(f, "{}", output)
}
}
#[cfg(test)]
mod tests {
use super::*;