improve board visuals

This commit is contained in:
Dmitry Fedotov
2025-04-07 02:11:09 +03:00
parent 3a00e077d8
commit d9f43036c3

View File

@@ -12,7 +12,7 @@ pub enum Cell {
impl std::fmt::Display for Cell {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
let mut s: &str = "";
let s: &str;
match *self {
Cell::CellX => s = "X",
Cell::CellO => s = "O",
@@ -118,7 +118,7 @@ impl std::fmt::Display for Board {
s.push_str(" 1 2 3 \n");
s.push_str(" ┌─┬─┬─┐\n");
s.push_str(" ┌───┬───┬───┐\n");
for i in 0..3 {
match i {
0 => s.push_str("a "),
@@ -127,16 +127,16 @@ impl std::fmt::Display for Board {
_ => {}
}
s.push_str(&format!(
"{}{}{}\n",
" {}{}{} \n",
self.cells[i * 3],
self.cells[i * 3 + 1],
self.cells[i * 3 + 2]
));
if i < 2 {
s.push_str(" ├─┼─┼─┤\n");
s.push_str(" ├───┼───┼───┤\n");
}
}
s.push_str(" └─┴─┴─┘\n");
s.push_str(" └───┴───┴───┘\n");
match self.has_winner() {
Some(w) => s.push_str(&format!("The winner is {w}")),