fn is_valid_neighbour(&self, x: usize, y: usize, direction: Direction) -> bool {
        use Direction::*;

        let mut count = 0;

        let xs = x.saturating_sub(1);
        let ys = y.saturating_sub(1);

        // do right / top / top right
        if !matches!(self.data.get(x + 1, y), Some(TileState::Wall) | None) && !matches!(direction, West) {
            count += 1;
        }

        if !matches!(self.data.get(x, y + 1), Some(TileState::Wall) | None) && !matches!(direction, South)
        {
            count += 1;
        }

        if !matches!(self.data.get(x + 1, y + 1), Some(TileState::Wall) | None)
            && !matches!(direction, South | West)
        {
            count += 1;
        }

        if !matches!(self.data.get(xs, y), Some(TileState::Wall) | None) && !matches!(direction, East)
        {
            count += 1;
        }

        if !matches!(self.data.get(xs, y + 1), Some(TileState::Wall) | None)
            && !matches!(direction, South | East)
        {
            count += 1;
        }

        // do bottom and bottom right
        if !matches!(self.data.get(x, ys), Some(TileState::Wall) | None) && !matches!(direction, North)
        {
            count += 1;
        }

        if !matches!(self.data.get(x + 1, ys), Some(TileState::Wall) | None)
            && !matches!(direction, North | West)
        {
            count += 1;
        }

        // bottom left
        if !matches!(self.data.get(xs, ys), Some(TileState::Wall) | None)
            && !matches!(direction, North | East)
        {
            count += 1;
        }

        count == 0 && matches!(self.visited.get(x, y), Some(false))
    }
// a tile is a valid neighbour if it is surrounded by walls / or one edge
// and it is unvisited
a tile is a valid neighbour if it is surrounded by walls / or one edge
and it is unvisited
a tile is a valid neighbour if it is surrounded by walls / or one edge and it is unvisited
fn is_valid_neighbour(&self, x: usize, y: usize, direction: Direction) -> bool {
        use Direction::*;
        let mut count = 0;
        let xs = x.saturating_sub(1);
        let ys = y.saturating_sub(1);
        // do right / top / top right
        if !matches!(self.data.get(x + 1, y), Some(TileState::Wall) | None) && !matches!(direction, West) {
            count += 1;
        }
        if !matches!(self.data.get(x, y + 1), Some(TileState::Wall) | None) && !matches!(direction, South)
        {
            count += 1;
        }
        if !matches!(self.data.get(x + 1, y + 1), Some(TileState::Wall) | None)
            && !matches!(direction, South | West)
        {
            count += 1;
        }
        if !matches!(self.data.get(xs, y), Some(TileState::Wall) | None) && !matches!(direction, East)
        {
            count += 1;
        }
        if !matches!(self.data.get(xs, y + 1), Some(TileState::Wall) | None)
            && !matches!(direction, South | East)
        {
            count += 1;
        }
        // do bottom and bottom right
        if !matches!(self.data.get(x, ys), Some(TileState::Wall) | None) && !matches!(direction, North)
        {
            count += 1;
        }
        if !matches!(self.data.get(x + 1, ys), Some(TileState::Wall) | None)
            && !matches!(direction, North | West)
        {
            count += 1;
        }
        // bottom left
        if !matches!(self.data.get(xs, ys), Some(TileState::Wall) | None)
            && !matches!(direction, North | East)
        {
            count += 1;
        }
        count == 0 && matches!(self.visited.get(x, y), Some(false))
    }
fn is_valid_neighbour ( & self , x : usize , y : usize , direction : Direction ) -> bool { use Direction :: * ; let mut count = 0 ; let xs = x . saturating_sub ( 1 ) ; let ys = y . saturating_sub ( 1 ) ; // do right / top / top right if ! matches ! ( self data get ( x 1 y ) Some ( TileState Wall ) None ) && ! matches ! ( direction West ) { count += 1 ; } if ! matches ! ( self data get ( x y 1 ) Some ( TileState Wall ) None ) && ! matches ! ( direction South ) { count += 1 ; } if ! matches ! ( self data get ( x 1 y 1 ) Some ( TileState Wall ) None ) && ! matches ! ( direction South West ) { count += 1 ; } if ! matches ! ( self data get ( xs y ) Some ( TileState Wall ) None ) && ! matches ! ( direction East ) { count += 1 ; } if ! matches ! ( self data get ( xs y 1 ) Some ( TileState Wall ) None ) && ! matches ! ( direction South East ) { count += 1 ; } // do bottom and bottom right if ! matches ! ( self data get ( x ys ) Some ( TileState Wall ) None ) && ! matches ! ( direction North ) { count += 1 ; } if ! matches ! ( self data get ( x 1 ys ) Some ( TileState Wall ) None ) && ! matches ! ( direction North West ) { count += 1 ; } // bottom left if ! matches ! ( self data get ( xs ys ) Some ( TileState Wall ) None ) && ! matches ! ( direction North East ) { count += 1 ; } count == 0 && matches ! ( self visited get ( x y ) Some ( false ) ) }
a tile is a valid neighbour if it is surrounded by walls / or one edge
and it is unvisited
a tile is a valid neighbour if it is surrounded by walls / or one edge and it is unvisited
&self
x
usize
y
usize
direction
Direction