Clean up flash function

This commit is contained in:
Tyler Hallada 2021-12-11 01:38:56 -05:00
parent 7dd99cab6d
commit f4a556940f

View File

@ -76,37 +76,23 @@ impl Cavern {
fn flash(&mut self, x: usize, y: usize) -> Vec<(usize, usize)> { fn flash(&mut self, x: usize, y: usize) -> Vec<(usize, usize)> {
let mut to_visit = vec![]; let mut to_visit = vec![];
if y > 0 { for (dx, dy) in vec![
self.grid[y - 1][x] += 1; (-1, -1),
to_visit.push((x, y - 1)); (-1, 0),
} (-1, 1),
if y < 9 { (0, -1),
self.grid[y + 1][x] += 1; (0, 0),
to_visit.push((x, y + 1)); (0, 1),
} (1, -1),
if x > 0 { (1, 0),
self.grid[y][x - 1] += 1; (1, 1),
to_visit.push((x - 1, y)); ] {
} let (x, y) = (x as isize + dx, y as isize + dy);
if x < 9 { if y >= 0 && y < 10 && x >= 0 && x < 10 {
self.grid[y][x + 1] += 1; let (x, y) = (x as usize, y as usize);
to_visit.push((x + 1, y)); self.grid[y][x] += 1;
} to_visit.push((x, y));
if y > 0 && x > 0 { }
self.grid[y - 1][x - 1] += 1;
to_visit.push((x - 1, y - 1));
}
if y > 0 && x < 9 {
self.grid[y - 1][x + 1] += 1;
to_visit.push((x + 1, y - 1));
}
if y < 9 && x > 0 {
self.grid[y + 1][x - 1] += 1;
to_visit.push((x - 1, y + 1));
}
if y < 9 && x < 9 {
self.grid[y + 1][x + 1] += 1;
to_visit.push((x + 1, y + 1));
} }
to_visit to_visit
} }