Iterate by Rank and File when building a diagram
This commit is contained in:
parent
aac1a85507
commit
c3e3ebfa97
1 changed files with 8 additions and 9 deletions
|
@ -1,8 +1,7 @@
|
|||
// Eryn Wells <eryn@erynwells.me>
|
||||
|
||||
use crate::{Position, Square};
|
||||
use std::fmt;
|
||||
use std::fmt::Write;
|
||||
use crate::{File, Position, Rank, Square};
|
||||
use std::{fmt, fmt::Write};
|
||||
|
||||
pub struct DiagramFormatter<'a>(&'a Position);
|
||||
|
||||
|
@ -18,11 +17,11 @@ impl<'a> fmt::Display for DiagramFormatter<'a> {
|
|||
|
||||
output.push_str(" +-----------------+\n");
|
||||
|
||||
for rank in (0..8).rev() {
|
||||
write!(output, "{} | ", rank + 1)?;
|
||||
for rank in Rank::ALL.iter().rev() {
|
||||
write!(output, "{} | ", rank)?;
|
||||
|
||||
for file in 0..8 {
|
||||
let square = Square::from_rank_file(rank, file).unwrap();
|
||||
for file in File::ALL.iter() {
|
||||
let square = Square::from_file_rank(*file, *rank);
|
||||
match self.0.piece_on_square(square) {
|
||||
Some(placed_piece) => write!(output, "{} ", placed_piece.piece())?,
|
||||
None => output.push_str(". "),
|
||||
|
@ -56,8 +55,8 @@ mod tests {
|
|||
fn one_king() {
|
||||
let mut pos = Position::empty();
|
||||
pos.place_piece(
|
||||
&Piece::king(Color::Black),
|
||||
&Square::from_algebraic_str("h3").expect("h3"),
|
||||
Piece::king(Color::Black),
|
||||
Square::from_algebraic_str("h3").expect("h3"),
|
||||
)
|
||||
.expect("Unable to place piece");
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue