feat: complete q8
This commit is contained in:
parent
3d47ae1a15
commit
8ce3754cb0
@ -149,5 +149,44 @@ class GreedyBustersAgent(BustersAgent):
|
||||
[beliefs for i, beliefs in enumerate(self.ghostBeliefs)
|
||||
if livingGhosts[i+1]]
|
||||
"*** YOUR CODE HERE ***"
|
||||
raiseNotDefined()
|
||||
|
||||
# find the position where the ghost most likely exist.
|
||||
livingGhostMostExistPosition = []
|
||||
for ghost in livingGhostPositionDistributions:
|
||||
max_belief = 0
|
||||
max_location = None
|
||||
for ghost_position, belief in ghost.items():
|
||||
if belief > max_belief:
|
||||
max_belief = belief
|
||||
max_location = ghost_position
|
||||
livingGhostMostExistPosition.append(max_location)
|
||||
|
||||
# find the nearest ghost
|
||||
min_distance = 1e9
|
||||
min_position = None
|
||||
for ghost_position in livingGhostMostExistPosition:
|
||||
distance = self.distancer.getDistance(pacmanPosition, ghost_position)
|
||||
if distance < min_distance:
|
||||
min_distance = distance
|
||||
min_position = ghost_position
|
||||
nearest_ghost_position = min_position
|
||||
|
||||
# find the new position which is closet with the ghost
|
||||
min_distance = 1e9
|
||||
min_action = None
|
||||
for action in legal:
|
||||
new_pacman_position = Actions.getSuccessor(pacmanPosition, action)
|
||||
distance = self.distancer.getDistance(new_pacman_position, nearest_ghost_position)
|
||||
if distance < min_distance:
|
||||
min_distance = distance
|
||||
min_action = action
|
||||
next_action = min_action
|
||||
|
||||
return next_action
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
"*** END YOUR CODE HERE ***"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user