From 04504b1f91ee5bf841c192a486e673eed501cb43 Mon Sep 17 00:00:00 2001 From: ZhuangYumin Date: Thu, 27 Jun 2024 01:44:48 +0000 Subject: [PATCH] reach 4/4 in q7 --- search/searchAgents.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/search/searchAgents.py b/search/searchAgents.py index 3cd26ca..4e02258 100644 --- a/search/searchAgents.py +++ b/search/searchAgents.py @@ -473,8 +473,21 @@ def foodHeuristic(state: Tuple[Tuple, List[List]], problem: FoodSearchProblem): problem.heuristicInfo['wallCount'] """ position, foodGrid = state - "*** YOUR CODE HERE ***" - return 0 + if foodGrid.count()==0: + return 0 + closet_food_dis=1e100 + closet_food=None + furthest_food_dis=-1e100 + furthest_food=None + for food in foodGrid.asList(): + dis=util.manhattanDistance(position,food) + if dis>furthest_food_dis: + furthest_food_dis=dis + furthest_food=food + if dis