/// Rotates the player's placement ship during the ship placement game state.
///
/// # Errors
///
/// Returns an error if the player does not have a placement ship.
Rotates the player's placement ship during the ship placement game state.
Rotates the player ' s placement ship during the ship placement game state .
pub fn rotate_placement_ship(&mut self) -> Result<(), &'static str> {
        let index = self.ships.len() - 1;
        let ship_len = self.ships[index].len() as u8;
        let dir = self.ships[index].dir().rotated();
        // If the current ship position would cause the rotation to position the ship partially out
        // of bounds, adjust the position such that the ship will be entirely within bounds.
        let old_head = self.ships[index].pos()[0];
        let new_head = match dir {
            Direction::North => [
                old_head[0],
                cmp::min(old_head[1], self.grid_size[1] - ship_len),
            ],
            Direction::East => [cmp::max(old_head[0], ship_len - 1), old_head[1]],
            Direction::South => [old_head[0], cmp::max(old_head[1], ship_len - 1)],
            Direction::West => [
                cmp::min(old_head[0], self.grid_size[0] - ship_len),
                old_head[1],
            ],
        };
        // get_ship_position() should always return Some(ship_pos) in this situation.
        let ship_pos = self.get_ship_position(new_head, dir, ship_len).unwrap();
        self.ships[index].set_pos(ship_pos)?;
        Ok(())
    }
pub fn rotate_placement_ship ( & mut self ) -> Result < ( ) , & ' static str > { let index = self . ships . len ( ) - 1 ; let ship_len = self . ships [ index ] . len ( ) as u8 ; let dir = self . ships [ index ] . dir ( ) . rotated ( ) ; // If the current ship position would cause the rotation to position the ship partially out // of bounds, adjust the position such that the ship will be entirely within bounds. let old_head = self . ships [ index ] . pos ( ) [ 0 ] ; let new_head = match dir { Direction :: North => [ old_head [ 0 ] , cmp :: min ( old_head [ 1 ] , self . grid_size [ 1 ] - ship_len ) , ] , Direction :: East => [ cmp :: max ( old_head [ 0 ] , ship_len - 1 ) , old_head [ 1 ] ] , Direction :: South => [ old_head [ 0 ] , cmp :: max ( old_head [ 1 ] , ship_len - 1 ) ] , Direction :: West => [ cmp :: min ( old_head [ 0 ] , self . grid_size [ 0 ] - ship_len ) , old_head [ 1 ] , ] , } ; // get_ship_position() should always return Some(ship_pos) in this situation. let ship_pos = self . get_ship_position ( new_head , dir , ship_len ) . unwrap ( ) ; self . ships [ index ] . set_pos ( ship_pos ) ? ; Ok ( ( ) ) }
Rotates the player's placement ship during the ship placement game state.
Rotates the player ' s placement ship during the ship placement game state .
&mut self
errors
Returns an error if the player does not have a placement ship.
Returns an error if the player does not have a placement ship .