remove moving tail of snake when begin moves are done and not calculate own body in avoid_snakes because already avoid own body
This commit is contained in:
@@ -35,6 +35,13 @@ class BetterMasterSnake(TemplateSnake):
|
||||
}
|
||||
}
|
||||
|
||||
def get_snake_body_without_snake_tail(self, snake:list[dict]):
|
||||
if len(set((pos["x"], pos["y"]) for pos in snake)) < 3:
|
||||
return snake
|
||||
|
||||
snake.pop()
|
||||
return snake
|
||||
|
||||
def avoid_my_body(self, my_body, possible_moves:dict) -> list:
|
||||
"""
|
||||
my_body: List of dictionaries of x/y coordinates for every segment of a Battlesnake.
|
||||
@@ -70,8 +77,11 @@ class BetterMasterSnake(TemplateSnake):
|
||||
def avoid_snakes(self, snakes:list, possible_moves:dict):
|
||||
remove = []
|
||||
for snake in snakes:
|
||||
if snake["id"] == self.my_snake["id"]:
|
||||
continue
|
||||
|
||||
for direction, location in possible_moves.items():
|
||||
if location in snake["body"]:
|
||||
if location in self.get_snake_body_without_snake_tail(snake["body"]):
|
||||
remove.append(direction)
|
||||
|
||||
remove = set(remove)
|
||||
|
||||
Reference in New Issue
Block a user