Meilleur bot lorsqu'il y a plusieurs balles #31
|
@ -528,10 +528,15 @@ def _update_bot(world: World):
|
|||
Fonction qui update les mouvement du bot
|
||||
"""
|
||||
# On récupère la balle la plus proche du bot
|
||||
ball_query = world.query(Position, Velocity, CollisionHandler)
|
||||
if ball_query == set():
|
||||
balls = world.query(Position, Velocity, CollisionHandler)
|
||||
if balls == set():
|
||||
return None
|
||||
ball = max(ball_query, key=lambda entity: entity[Position].y)
|
||||
right_balls = [ball for ball in balls if ball[Velocity].x > 0]
|
||||
left_balls = [ball for ball in balls if ball[Velocity].x < 0]
|
||||
if len(right_balls) != 0:
|
||||
ball = max(right_balls, key=lambda entity: entity[Position].x)
|
||||
else:
|
||||
ball = min(left_balls, key=lambda entity: entity[Position].x)
|
||||
|
||||
# On récupère le bot et le joueur
|
||||
bot = world.query(Player2).pop()
|
||||
|
|
Loading…
Reference in a new issue