def remove_matching(self, bubbles):
bubble_old = []
for bubble in list(bubbles):
if self.color == bubble.color and self.collide(bubble):
bubble_old = bubble
bubbles.remove(bubble)
self.touching(bubble_old, bubbles)
return True
return False
this is the method that calls it.
The code works when the bubbles are lined up like this
x O x
x O x
x O x
O <-current ball
x O x
x O x
O O O
O <-current ball
the issue happens with anything like this
O O
O O
O <-current ball
I have also tried this
def touching(self, bubble, bubbles):
for bubble1 in list(bubbles):
if self.color == bubble1.color and dist(bubble.pos, bubble1.pos) <= 2 * BUBBLE_RADIUS:
bubbles.remove(bubble_old)
self.touching(bubble1, bubbles)
I got the same error
and this gets this error RuntimeError: Set changed size during iteration
def touching(self, bubble, bubbles):
for bubble1 in iter(bubbles):
if self.color == bubble1.color and dist(bubble.pos, bubble1.pos) <= 2 * BUBBLE_RADIUS:
bubbles.remove(bubble1)
self.touching(bubble1, bubbles)