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 ***"