improve board visuals
This commit is contained in:
@@ -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",
|
||||||
@@ -118,7 +118,7 @@ impl std::fmt::Display for Board {
|
|||||||
|
|
||||||
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}")),
|
||||||
|
Reference in New Issue
Block a user