wip incremental distance update
This commit is contained in:
parent
2bf743a272
commit
3bd28451e9
3 changed files with 55 additions and 14 deletions
|
|
@ -201,12 +201,20 @@ impl Default for GameState {
|
|||
|
||||
impl Display for GameState {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let dm = GoalDistanceMap::new(&self.walls, self.current_player);
|
||||
let d1 = GoalDistanceMap::new(&self.walls, PlayerIdentifier::P1);
|
||||
let d2 = GoalDistanceMap::new(&self.walls, PlayerIdentifier::P2);
|
||||
|
||||
writeln!(
|
||||
f,
|
||||
"P1: {}, P2: {}\n",
|
||||
self.p1.walls_left, self.p2.walls_left
|
||||
"P1: {} walls, {} away from win",
|
||||
self.p1.walls_left,
|
||||
d1.at(self.p1.x(), self.p1.y())
|
||||
)?;
|
||||
writeln!(
|
||||
f,
|
||||
"P2: {} walls, {} away from win",
|
||||
self.p2.walls_left,
|
||||
d2.at(self.p2.x(), self.p2.y())
|
||||
)?;
|
||||
writeln!(f, "┏━━┬━━┬━━┬━━┬━━┬━━┬━━┬━━┬━━┓")?;
|
||||
for y in 0..9 {
|
||||
|
|
@ -237,11 +245,12 @@ impl Display for GameState {
|
|||
write!(f, "{wall}")?;
|
||||
}
|
||||
let player = if self.p1.x() == x && self.p1.y() == y {
|
||||
"\x1b[1mP1\x1b[0m".to_string()
|
||||
"\x1b[1mP1\x1b[0m".to_owned()
|
||||
} else if self.p2.x() == x && self.p2.y() == y {
|
||||
"\x1b[1mP2\x1b[0m".to_string()
|
||||
"\x1b[1mP2\x1b[0m".to_owned()
|
||||
} else {
|
||||
format!("{:^2}", dm.at(x, y))
|
||||
// format!("{:^2}", dm.at(x, y))
|
||||
" ".to_owned()
|
||||
};
|
||||
write!(f, "{player}")?;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue