add function when not eat food to remove snake tail

This commit is contained in:
2024-05-08 23:45:07 +02:00
parent 80b7c4df89
commit e068fb8614
2 changed files with 24 additions and 2 deletions
+1
View File
@@ -72,6 +72,7 @@ class BetterMasterSnake(TemplateSnake):
if len(self.food_positions) > 0:
# Choose the closest food source based on the heuristic
closest_food = min(self.food_positions, key=lambda food: abs(food['x'] - self.game_board.get_my_snake_head()['x']) + abs(food['y'] - self.game_board.get_my_snake_head()['y']))
self.set_target_food(closest_food)
# Use A* to search for a safe path
return self.a_star_search(self.game_board.get_my_snake_head(), closest_food, obstacles)