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