Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _excavate_love_triangles(self):
"""Recognize character love triangles that have emerged in a simulation instance."""
love_triangles = []
for first_person in self.simulation.town.residents:
first_person_love_interests = set(first_person.is_captivated_by)
for second_person in first_person_love_interests:
second_person_love_interests = set(second_person.is_captivated_by)
if first_person not in second_person_love_interests:
for third_person in second_person_love_interests:
third_person_love_interests = set(third_person.is_captivated_by)
if second_person not in third_person_love_interests:
if first_person in third_person_love_interests:
subjects = (first_person, second_person, third_person)
if not any(lt for lt in love_triangles if set(lt.subjects) == set(subjects)):
love_triangles.append(LoveTriangle(subjects=subjects))
return love_triangles