Refactored shipExists to isLegalShip and made separate function for boundary checking called isOutOfBounds…