save direction to kill the snake use the correct kill direction in overwrite_eat_the_other_snake can end in a draw when both heads are by the food

This commit is contained in:
2024-04-17 12:22:54 +02:00
parent a57536b7cb
commit 034b0e361a
2 changed files with 8 additions and 41 deletions
+3 -2
View File
@@ -122,10 +122,11 @@ class TemplateSnake:
for snake in self.other_snakes:
for direction, location in self.safe_positions.items():
if len(self.safe_positions) > 1:
#TODO: Avoid Draw when heads are by the food
if snake["length"] < self.my_snake["length"] and location in [{"x": v["x"], "y": v["y"]} for k, v in self.get_possible_moves(snake["head"]).items()]:
self.eat_the_snake_overwrite = True
return direction
#TODO: Check if snake on the way to the bood here and only remove this pos
self.kill_the_snake = direction
#TODO: Check if snake on the way to the food here and only remove this pos
elif location in [{"x": v["x"], "y": v["y"]} for k, v in self.get_possible_moves(snake["head"]).items()]:
remove.append(direction)