/// Returns the coordinates of a movement from `pos` in a `direction`.
/// Returns `None` if the movement is not possible.
Returns the coordinates of a movement from `pos` in a `direction`.
Returns `None` if the movement is not possible.
Returns the coordinates of a movement from ` pos ` in a ` direction ` . Returns ` None ` if the movement is not possible .
fn movement(&self, pos: &[u8; 2], direction: Direction) -> Option<[u8; 2]> {
        let valid = match direction {
            Direction::North => pos[1] > 0,
            Direction::East => pos[0] < self.grid_size[0] - 1,
            Direction::South => pos[1] < self.grid_size[1] - 1,
            Direction::West => pos[0] > 0,
        };
        match valid {
            true => Some(match direction {
                Direction::North => [pos[0], pos[1] - 1],
                Direction::East => [pos[0] + 1, pos[1]],
                Direction::South => [pos[0], pos[1] + 1],
                Direction::West => [pos[0] - 1, pos[1]],
            }),
            false => None,
        }
    }
fn movement ( & self , pos : & [ u8 ; 2 ] , direction : Direction ) -> Option < [ u8 ; 2 ] > { let valid = match direction { Direction :: North => pos [ 1 ] > 0 , Direction :: East => pos [ 0 ] < self . grid_size [ 0 ] - 1 , Direction :: South => pos [ 1 ] < self . grid_size [ 1 ] - 1 , Direction :: West => pos [ 0 ] > 0 , } ; match valid { true => Some ( match direction { Direction :: North => [ pos [ 0 ] , pos [ 1 ] - 1 ] , Direction :: East => [ pos [ 0 ] + 1 , pos [ 1 ] ] , Direction :: South => [ pos [ 0 ] , pos [ 1 ] + 1 ] , Direction :: West => [ pos [ 0 ] - 1 , pos [ 1 ] ] , } ) , false => None , } }
Returns the coordinates of a movement from `pos` in a `direction`.
Returns the coordinates of a movement from ` pos ` in a ` direction ` .
&self
pos
&[u8; 2]
direction
Direction