def trouver_cap(self):
    'Trouve le cap, tenant compte des obstacles.'
    equipage = self.equipage
    navire = self.navire
    if self.doit_reculer:
        (x, y) = self.doit_reculer
        p_x = navire.position.x
        p_y = navire.position.y
        max_distance = navire.get_max_distance_au_centre()
        if (sqrt((((x - p_x) ** 2) + ((y - p_y) ** 2))) > (max_distance + 1)):
            self.doit_reculer = ()
        else:
            return
    tries = equipage.vigie_tries
    if (not tries):
        self.autre_direction = None
        self.transmettre_controles()
        return
    obstacles = tries.get('obstacle', {}).copy()
    obstacles.update(tries.get('salle', {}))
    obstacles.update(tries.get('sallenavire', {}))
    dangereux = obstacles.copy()
    for angle in obstacles.keys():
        if ((angle < (- 90)) or (angle > 90)):
            del dangereux[angle]
    if (not dangereux):
        self.ancienne_vitesse = None
        self.autre_direction = None
        self.transmettre_controles()
        return
    min_angle = None
    min_distance = None
    for (angle, (vecteur, point)) in dangereux.items():
        if ((min_distance is None) or (vecteur.mag < min_distance)):
            min_distance = vecteur.mag
            min_angle = angle
    if ((- 45) <= min_angle <= 45):
        if (min_distance <= 2):
            self.vitesse = 0.05
        elif (min_distance < 10):
            self.vitesse = 0.2
        elif (min_distance < 25):
            self.vitesse = 0.6
    distance = 30
    angles = [(i * 5) for i in range(0, 35)]
    for i in range(1, 35):
        angles.append((i * (- 5)))
    o_distance = self.get_distance()
    if (o_distance.norme < 30):
        distance = o_distance.norme
    relative = (o_distance.direction - navire.direction.direction)
    angles = sorted(angles, key=(lambda a: fabs((a - relative))))
    position = navire.opt_position
    while (distance > 0):
        for angle in angles:
            vecteur = navire.opt_direction
            vecteur.mag = distance
            vecteur.around_z(radians(angle))
            if (not navire.controller_collision(vecteur, collision=False, marge=0.8)):
                if (angle != 0):
                    self.info('Cap libre sur {}°'.format(angle))
                self.autre_direction = round(((navire.direction.direction + angle) % 360))
                if (fabs(angle) > 30):
                    self.vitesse = 0
                self.transmettre_controles()
                return
        distance -= 5
    self.transmettre_controles()
Trouve le cap, tenant compte des obstacles.
def trouver_cap(self):
    
    equipage = self.equipage
    navire = self.navire
    if self.doit_reculer:
        (x, y) = self.doit_reculer
        p_x = navire.position.x
        p_y = navire.position.y
        max_distance = navire.get_max_distance_au_centre()
        if (sqrt((((x - p_x) ** 2) + ((y - p_y) ** 2))) > (max_distance + 1)):
            self.doit_reculer = ()
        else:
            return
    tries = equipage.vigie_tries
    if (not tries):
        self.autre_direction = None
        self.transmettre_controles()
        return
    obstacles = tries.get('obstacle', {}).copy()
    obstacles.update(tries.get('salle', {}))
    obstacles.update(tries.get('sallenavire', {}))
    dangereux = obstacles.copy()
    for angle in obstacles.keys():
        if ((angle < (- 90)) or (angle > 90)):
            del dangereux[angle]
    if (not dangereux):
        self.ancienne_vitesse = None
        self.autre_direction = None
        self.transmettre_controles()
        return
    min_angle = None
    min_distance = None
    for (angle, (vecteur, point)) in dangereux.items():
        if ((min_distance is None) or (vecteur.mag < min_distance)):
            min_distance = vecteur.mag
            min_angle = angle
    if ((- 45) <= min_angle <= 45):
        if (min_distance <= 2):
            self.vitesse = 0.05
        elif (min_distance < 10):
            self.vitesse = 0.2
        elif (min_distance < 25):
            self.vitesse = 0.6
    distance = 30
    angles = [(i * 5) for i in range(0, 35)]
    for i in range(1, 35):
        angles.append((i * (- 5)))
    o_distance = self.get_distance()
    if (o_distance.norme < 30):
        distance = o_distance.norme
    relative = (o_distance.direction - navire.direction.direction)
    angles = sorted(angles, key=(lambda a: fabs((a - relative))))
    position = navire.opt_position
    while (distance > 0):
        for angle in angles:
            vecteur = navire.opt_direction
            vecteur.mag = distance
            vecteur.around_z(radians(angle))
            if (not navire.controller_collision(vecteur, collision=False, marge=0.8)):
                if (angle != 0):
                    self.info('Cap libre sur {}°'.format(angle))
                self.autre_direction = round(((navire.direction.direction + angle) % 360))
                if (fabs(angle) > 30):
                    self.vitesse = 0
                self.transmettre_controles()
                return
        distance -= 5
    self.transmettre_controles()