pub fn sink_ship_if_all_hit(&mut self, pos: &[u8; 2]) -> Result<bool, &'static str> {
        if let Some(index) = self.ships.iter().position(|s| s.pos().contains(pos)) {
            let sunk = self.ships[index]
                .pos()
                .iter()
                .all(|p| self.space(p).is_hit());

            if sunk {
                self.ships[index].set_sunk()?;
            }

            Ok(sunk)
        } else {
            Err("no ship at the given position")
        }
    }
/// Sets the ship at the given position as sunk if all spaces it occupies
/// have been checked, and returns whether the ship was sunk.
///
/// # Errors
///
/// Returns an error if no ship is at the given position, or if the ship
/// state is not active.
Sets the ship at the given position as sunk if all spaces it occupies
have been checked, and returns whether the ship was sunk.
Sets the ship at the given position as sunk if all spaces it occupies have been checked and returns whether the ship was sunk .
pub fn sink_ship_if_all_hit(&mut self, pos: &[u8; 2]) -> Result<bool, &'static str> {
        if let Some(index) = self.ships.iter().position(|s| s.pos().contains(pos)) {
            let sunk = self.ships[index]
                .pos()
                .iter()
                .all(|p| self.space(p).is_hit());
            if sunk {
                self.ships[index].set_sunk()?;
            }
            Ok(sunk)
        } else {
            Err("no ship at the given position")
        }
    }
pub fn sink_ship_if_all_hit ( & mut self , pos : & [ u8 ; 2 ] ) -> Result < bool , & ' static str > { if let Some ( index ) = self . ships . iter ( ) . position ( | s | s . pos ( ) . contains ( pos ) ) { let sunk = self . ships [ index ] . pos ( ) . iter ( ) . all ( | p | self . space ( p ) . is_hit ( ) ) ; if sunk { self . ships [ index ] . set_sunk ( ) ? ; } Ok ( sunk ) } else { Err ( " " ) } }
Sets the ship at the given position as sunk if all spaces it occupies
have been checked, and returns whether the ship was sunk.
Sets the ship at the given position as sunk if all spaces it occupies have been checked and returns whether the ship was sunk .
&mut self
pos
&[u8; 2]
&mut self
pos
&[u8; 2]
errors
Returns an error if no ship is at the given position, or if the ship
state is not active.
Returns an error if no ship is at the given position or if the ship state is not active .