[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:
parent
7f4485ed51
commit
7071f6a742
3 changed files with 10 additions and 6 deletions
|
@ -8,8 +8,7 @@ mod r#move;
|
||||||
mod macros;
|
mod macros;
|
||||||
mod move_generator;
|
mod move_generator;
|
||||||
pub mod piece;
|
pub mod piece;
|
||||||
#[macro_use]
|
mod position;
|
||||||
pub mod position;
|
|
||||||
mod sight;
|
mod sight;
|
||||||
mod square;
|
mod square;
|
||||||
|
|
||||||
|
|
|
@ -4,10 +4,11 @@ use super::{flags::Flags, piece_sets::PieceBitBoards, Pieces};
|
||||||
use crate::{
|
use crate::{
|
||||||
move_generator::Moves,
|
move_generator::Moves,
|
||||||
piece::{Color, Piece, PlacedPiece, Shape},
|
piece::{Color, Piece, PlacedPiece, Shape},
|
||||||
|
position::DiagramFormatter,
|
||||||
sight::Sight,
|
sight::Sight,
|
||||||
BitBoard, Move, Square,
|
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
|
/// 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
|
/// 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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::position;
|
use crate::position;
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use board::piece::{Color, Piece, Shape};
|
use board::piece::{Color, Piece, Shape};
|
||||||
use board::position::DiagramFormatter;
|
|
||||||
use board::{Position, Square};
|
use board::{Position, Square};
|
||||||
use clap::{Arg, Command};
|
use clap::{Arg, Command};
|
||||||
use rustyline::error::ReadlineError;
|
use rustyline::error::ReadlineError;
|
||||||
|
@ -80,8 +79,7 @@ fn main() -> Result<(), String> {
|
||||||
let mut pos = Position::empty();
|
let mut pos = Position::empty();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let diagram = DiagramFormatter::new(&pos);
|
println!("{}", &pos);
|
||||||
println!("{}", diagram);
|
|
||||||
|
|
||||||
let readline = editor.readline("? ");
|
let readline = editor.readline("? ");
|
||||||
match readline {
|
match readline {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue