prettier board

This commit is contained in:
Julia Ryan 2025-09-11 11:43:33 -07:00
parent 672f9e09bf
commit d4e626d13c
No known key found for this signature in database

View file

@ -117,14 +117,6 @@ impl Default for GameState {
}
}
/*
what we're going for:
-- -- --
| | |P2|
-- -- --
|P1| | |
-- -- --
*/
impl Display for GameState {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(
@ -132,42 +124,46 @@ impl Display for GameState {
"P1: {}, P2: {}\n",
self.p1.walls_left, self.p2.walls_left
)?;
writeln!(f, "┏━━┬━━┬━━┬━━┬━━┬━━┬━━┬━━┬━━┓")?;
for y in 0..9 {
for x in 0..9 {
if y > 0 {
let wall = if !self.walls.can_walk_between(x, y - 1, x, y) {
write!(f, "")?;
for x in 0..9 {
let wall = if self.walls.can_walk_between(x, y - 1, x, y) {
' '
} else {
'-'
''
};
write!(f, "{wall}{wall}")?;
}
if x != 8 {
write!(f, " ")?;
write!(f, "")?;
}
}
writeln!(f, "")?;
write!(f, "\n")?;
} else {
write!(f, "")?;
}
for x in 0..9 {
if x > 0 {
let wall = if !self.walls.can_walk_between(x - 1, y, x, y) {
let wall = if self.walls.can_walk_between(x - 1, y, x, y) {
' '
} else {
'|'
''
};
write!(f, "{wall}")?;
}
let player = if self.p1.x() == x && self.p1.y() == y {
let player = if self.p1.x() == x && 8 - self.p1.y() == y {
"P1"
} else if self.p2.x() == x && self.p2.y() == y {
} else if self.p2.x() == x && 8 - self.p2.y() == y {
"P2"
} else {
" "
};
write!(f, "{player}")?;
}
writeln!(f, "")?;
writeln!(f, "")?;
}
writeln!(f, "")?;
writeln!(f, "┗━━┴━━┴━━┴━━┴━━┴━━┴━━┴━━┴━━┛")?;
Ok(())
}
}