improved default display

This commit is contained in:
JOLIMAITRE Matthieu 2022-05-30 02:50:44 +03:00
parent 82912dbc44
commit 33f808f0ad

View file

@ -163,25 +163,26 @@ where
fn draw(maze: &Maze, tried: &HashSet<Pos>, tick: usize, path: &Vec<Pos>) { fn draw(maze: &Maze, tried: &HashSet<Pos>, tick: usize, path: &Vec<Pos>) {
let mut overlay = HashMap::new(); let mut overlay = HashMap::new();
for position in tried { for position in tried {
overlay.insert(*position, '#'); overlay.insert(*position, '');
} }
for position in path { for position in path {
overlay.insert(*position, 'P'); overlay.insert(*position, '');
} }
overlay.insert(maze.start(), 'S');
overlay.insert(maze.end(), 'E');
overlay.insert(*path.last().unwrap(), 'G');
overlay.insert(*path.last().unwrap(), 'x'); let grid = maze.display(Some(overlay));
let text = format!("tick {tick}:\n{grid}\n");
let text = maze.display(Some(overlay));
// DIRTY! // DIRTY!
// print the frame on top of the previous one // print the frame on top of the previous one
if tick > 0 { if tick > 0 {
let count = text.lines().count() + 1; let count = text.lines().count();
let up = termion::cursor::Up(count as u16); let up = termion::cursor::Up(count as u16);
print!("{up}") print!("{up}")
} }
print!("tick {tick}:\n{text}\n"); print!("{text}");
} }
} }