Skip to content

Commit ccc93c8

Browse files
committed
Parse the step as a better Sans notion.
1 parent 5c557df commit ccc93c8

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/piece.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ impl Piece {
4747
impl fmt::Display for PieceType {
4848
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4949
let display_name = match self {
50-
PieceType::King => "King",
51-
PieceType::Queen => "Queen",
52-
PieceType::Bishop => "Bishop",
53-
PieceType::Rook => "Rook",
54-
PieceType::Knight => "Knight",
55-
PieceType::Pawn => "Pawn",
50+
PieceType::King => "K",
51+
PieceType::Queen => "Q",
52+
PieceType::Bishop => "B",
53+
PieceType::Rook => "R",
54+
PieceType::Knight => "N",
55+
PieceType::Pawn => "",
5656
};
5757
write!(f, "{}", display_name)
5858
}

src/ui/solution.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,22 @@ use crate::step::Step;
44

55
#[component]
66
pub fn Solution(steps: Vec<Step>) -> Element {
7+
let sans = to_sans(&steps).join(" ");
78
rsx! {
8-
h2 { "Steps" }
9-
p { {format!("{:?}", steps)} }
9+
p { {sans} }
1010
}
1111
}
12+
13+
fn to_sans(steps: &[Step]) -> Vec<String> {
14+
let mut sans_step = vec![];
15+
16+
let numeric_to_sans = |r: usize, c: usize| -> String {
17+
format!("{}{}", (c as u8 + b'a') as char, 8 - r)
18+
};
19+
20+
for Step { from: (fr, fc), to: (tr, tc), piece_type } in steps {
21+
let tmp = format!("{}{}x{}", piece_type.to_string(), numeric_to_sans(*fr, *fc), numeric_to_sans(*tr, *tc));
22+
sans_step.push(tmp);
23+
}
24+
sans_step
25+
}

0 commit comments

Comments
 (0)