add function when not eat food to remove snake tail
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user