B:BD[
2.541] → [
2.541:609]
fn time_step(grid: &Vec<Vec<LobbyPoint>>) -> Vec<Vec<LobbyPoint>> {
fn build_neighbourhoods_v1(grid: &Vec<Vec<LobbyPoint>>) -> Vec<Vec<Vec<(usize,usize)>>> {
grid.into_iter().enumerate().map(|(y,row)|
row.into_iter().enumerate().map(move |(x,lp)|
match lp {
LobbyPoint::Floor => vec![],
_ => neighbours(x,y).flat_map(|(xn,yn)|
usize::try_from(yn).ok().and_then(|yn|
grid.get(yn).and_then(|row|
usize::try_from(xn).ok().and_then(|xn|
row.get(xn).and_then(|lp|
match lp {
LobbyPoint::Floor => None,
_ => Some((xn,yn)),
}
)
)
)
).into_iter()
).collect(),
}
).collect()
).collect()
}
fn seek_line(x0: usize, y0: usize, xd: isize, yd: isize, grid: &Vec<Vec<LobbyPoint>>) -> Option<(usize,usize)> {
let x = x0.wrapping_add(xd as usize);
let y = y0.wrapping_add(yd as usize);
grid.get(y).and_then(|row| row.get(x)).and_then(|lp| match lp {
LobbyPoint::Floor => seek_line(x, y, xd, yd, grid),
_ => Some((x,y))
})
}
fn neighbours_v2<'a>(xc: usize, yc: usize, grid: &'a Vec<Vec<LobbyPoint>>) -> impl Iterator<Item=(usize,usize)> + 'a {
(-1 .. 2).flat_map(move |y| (-1 .. 2).map(move |x| (x,y)))
.filter(|p| *p != (0,0))
.flat_map(move |(x,y)| seek_line(xc,yc,x,y,grid).into_iter())
}
fn build_neighbourhoods_v2(grid: &Vec<Vec<LobbyPoint>>) -> Vec<Vec<Vec<(usize,usize)>>> {