From f1c5e52ef7791ce88ad18eaba9adbc132769478d Mon Sep 17 00:00:00 2001 From: ZhuangYumin Date: Thu, 4 Jul 2024 01:54:50 +0000 Subject: [PATCH] tracking q8 --- tracking/bustersAgents.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/tracking/bustersAgents.py b/tracking/bustersAgents.py index a6fd060..71c68b3 100644 --- a/tracking/bustersAgents.py +++ b/tracking/bustersAgents.py @@ -149,5 +149,26 @@ class GreedyBustersAgent(BustersAgent): [beliefs for i, beliefs in enumerate(self.ghostBeliefs) if livingGhosts[i+1]] "*** YOUR CODE HERE ***" - raiseNotDefined() + # Find the most likely position of each ghost + ghostPositions = [] + for beliefs in livingGhostPositionDistributions: + ghostPositions.append(beliefs.argMax()) + # Find the closest ghost + closestGhost = None + closestDistance = float('inf') + for ghost in ghostPositions: + distance = self.distancer.getDistance(pacmanPosition, ghost) + if distance < closestDistance: + closestDistance = distance + closestGhost = ghost + # Find the closest action to the closest ghost + closestAction = None + closestDistance = float('inf') + for action in legal: + successorPosition = Actions.getSuccessor(pacmanPosition, action) + distance = self.distancer.getDistance(successorPosition, closestGhost) + if distance < closestDistance: + closestDistance = distance + closestAction = action + return closestAction "*** END YOUR CODE HERE ***"