fn adjacents_in_basin(
    c: Coord,
    terrain: &Vec<Vec<u8>>,
    basin_map: &mut Vec<Vec<u8>>,
) -> Vec<Coord> {
    // create a vec of coords pointing in every cardinal direction, then filter out the ones that
    // aren't part of the basin (due to being equal to the breadcrumb, or out of bounds, or equal
    // to 9)
    let to_search: Vec<Coord> = vec![c.inc_x(), c.dec_x(), c.inc_y(), c.dec_y()]
        .iter()
        .filter(|c| in_range(c, terrain))
        .filter(|c| basin_map[c.y as usize][c.x as usize] == 0) // filter out already visited
        .filter(|c| terrain[c.y as usize][c.x as usize] < 9) // not a wall
        .map(|c| c.clone())
        .collect();

    // mark this position in the basin map
    to_search
        .iter()
        .for_each(|c| basin_map[c.y as usize][c.x as usize] = 1);

    to_search
}
/// Given an x and y point, find any adjacent (up, down, left, right) values that are members of
/// the same basin.
Given an x and y point, find any adjacent (up, down, left, right) values that are members of
the same basin.
Given an x and y point find any adjacent ( up down left right ) values that are members of the same basin .
fn adjacents_in_basin(
    c: Coord,
    terrain: &Vec<Vec<u8>>,
    basin_map: &mut Vec<Vec<u8>>,
) -> Vec<Coord> {
    // create a vec of coords pointing in every cardinal direction, then filter out the ones that
    // aren't part of the basin (due to being equal to the breadcrumb, or out of bounds, or equal
    // to 9)
    let to_search: Vec<Coord> = vec![c.inc_x(), c.dec_x(), c.inc_y(), c.dec_y()]
        .iter()
        .filter(|c| in_range(c, terrain))
        .filter(|c| basin_map[c.y as usize][c.x as usize] == 0) // filter out already visited
        .filter(|c| terrain[c.y as usize][c.x as usize] < 9) // not a wall
        .map(|c| c.clone())
        .collect();
    // mark this position in the basin map
    to_search
        .iter()
        .for_each(|c| basin_map[c.y as usize][c.x as usize] = 1);
    to_search
}
fn adjacents_in_basin ( c : Coord , terrain : & Vec < Vec < u8 > > , basin_map : & mut Vec < Vec < u8 > > , ) -> Vec < Coord > { // create a vec of coords pointing in every cardinal direction, then filter out the ones that // aren't part of the basin (due to being equal to the breadcrumb, or out of bounds, or equal // to 9) let to_search : Vec < Coord > = vec ! [ c inc_x ( ) c dec_x ( ) c inc_y ( ) c dec_y ( ) ] . iter ( ) . filter ( | c | in_range ( c , terrain ) ) . filter ( | c | basin_map [ c . y as usize ] [ c . x as usize ] == 0 ) // filter out already visited . filter ( | c | terrain [ c . y as usize ] [ c . x as usize ] < 9 ) // not a wall . map ( | c | c . clone ( ) ) . collect ( ) ; // mark this position in the basin map to_search . iter ( ) . for_each ( | c | basin_map [ c . y as usize ] [ c . x as usize ] = 1 ) ; to_search }
Given an x and y point, find any adjacent (up, down, left, right) values that are members of
the same basin.
Given an x and y point find any adjacent ( up down left right ) values that are members of the same basin .
c
Coord
terrain
&Vec<Vec<u8>>
basin_map
&mut Vec<Vec<u8>>