[board] Cave to pressure and implement fmt::Display for Position

It prints a nice diagram!

Now I can make the position module private.
This commit is contained in:
Eryn Wells 2024-01-19 18:11:27 -08:00
parent 7f4485ed51
commit 7071f6a742
3 changed files with 10 additions and 6 deletions

View file

@ -8,8 +8,7 @@ mod r#move;
mod macros;
mod move_generator;
pub mod piece;
#[macro_use]
pub mod position;
mod position;
mod sight;
mod square;

View file

@ -4,10 +4,11 @@ use super::{flags::Flags, piece_sets::PieceBitBoards, Pieces};
use crate::{
move_generator::Moves,
piece::{Color, Piece, PlacedPiece, Shape},
position::DiagramFormatter,
sight::Sight,
BitBoard, Move, Square,
};
use std::cell::OnceCell;
use std::{cell::OnceCell, 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
@ -211,6 +212,12 @@ impl Default for Position {
}
}
impl fmt::Display for Position {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", DiagramFormatter::new(self))
}
}
#[cfg(test)]
mod tests {
use crate::position;

View file

@ -1,5 +1,4 @@
use board::piece::{Color, Piece, Shape};
use board::position::DiagramFormatter;
use board::{Position, Square};
use clap::{Arg, Command};
use rustyline::error::ReadlineError;
@ -80,8 +79,7 @@ fn main() -> Result<(), String> {
let mut pos = Position::empty();
loop {
let diagram = DiagramFormatter::new(&pos);
println!("{}", diagram);
println!("{}", &pos);
let readline = editor.readline("? ");
match readline {