Fix bug in fruit slices

This commit is contained in:
Chris Proctor
2026-03-19 13:19:29 -04:00
parent d504fd6a05
commit 57444521cc
2 changed files with 15 additions and 13 deletions

View File

@@ -77,19 +77,20 @@ class Catcher:
agent.parent.check_catcher_collision(game) agent.parent.check_catcher_collision(game)
def _slice_fruits(self, game): def _slice_fruits(self, game):
width, height = game.board_size _, height = game.board_size
agents_by_pos = game.get_agents_by_position() slice_rows = set(range(height - 3, height))
seen = set() manager = game.get_agent_by_name("fruit_manager")
for y in range(height - 3, height): for fruit in list(manager.active_fruits):
for x in range(width): if not fruit.alive:
for agent in agents_by_pos.get((x, y), []): continue
if isinstance(agent, FruitPiece) and agent.parent.alive and id(agent.parent) not in seen: for piece in fruit.pieces.values():
seen.add(id(agent.parent)) if piece.position[1] in slice_rows:
game.state['score'] += 1 game.state['score'] += 1
for p in agent.parent.pieces.values(): for p in fruit.pieces.values():
game.remove_agent(p) game.remove_agent(p)
game.remove_agent(agent.parent) game.remove_agent(fruit)
agent.parent.alive = False fruit.alive = False
break
def create_pieces(self, game): def create_pieces(self, game):
x, y = self.position x, y = self.position

View File

@@ -4,6 +4,7 @@ from random import choice, randint
class FruitManager: class FruitManager:
display = False display = False
name = "fruit_manager"
def __init__(self): def __init__(self):
self.active_fruits = [] self.active_fruits = []