tracking q5
This commit is contained in:
@ -354,7 +354,11 @@ class DiscreteDistribution(dict):
|
||||
{}
|
||||
"""
|
||||
"*** YOUR CODE HERE ***"
|
||||
raiseNotDefined()
|
||||
total_prob = self.total()
|
||||
if total_prob == 0:
|
||||
return
|
||||
for key in self.keys():
|
||||
self[key] /= total_prob
|
||||
"*** END YOUR CODE HERE ***"
|
||||
|
||||
def sample(self):
|
||||
@ -379,7 +383,15 @@ class DiscreteDistribution(dict):
|
||||
0.0
|
||||
"""
|
||||
"*** YOUR CODE HERE ***"
|
||||
raiseNotDefined()
|
||||
total_prob = self.total()
|
||||
if total_prob == 0:
|
||||
return None
|
||||
rand_num = random.random() * total_prob
|
||||
for key in self.keys():
|
||||
rand_num -= self[key]
|
||||
if rand_num <= 0:
|
||||
return key
|
||||
return key
|
||||
"*** END YOUR CODE HERE ***"
|
||||
|
||||
|
||||
@ -454,7 +466,19 @@ class InferenceModule:
|
||||
Return the probability P(noisyDistance | pacmanPosition, ghostPosition).
|
||||
"""
|
||||
"*** YOUR CODE HERE ***"
|
||||
raiseNotDefined()
|
||||
if(jailPosition==ghostPosition):
|
||||
if noisyDistance==None:
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
if noisyDistance==None:
|
||||
# the ghost is in the jail
|
||||
if ghostPosition==jailPosition:
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
true_distance=manhattanDistance(pacmanPosition,ghostPosition)
|
||||
return busters.getObservationProbability(noisyDistance,true_distance)
|
||||
"*** END YOUR CODE HERE ***"
|
||||
|
||||
def setGhostPosition(self, gameState, ghostPosition, index):
|
||||
|
Reference in New Issue
Block a user