Finish project 4.
This commit is contained in:
parent
5f66554cdb
commit
2fd09bb7b8
@ -478,18 +478,17 @@ class JointParticleFilter:
|
||||
|
||||
distribution, samples = [], []
|
||||
for particle in self.particles:
|
||||
weight = 1 # weight is likelihood over whole particle
|
||||
weight = 1.0 # weight is likelihood over whole particle
|
||||
particle = tuple(particle)
|
||||
for ghostIndex in range(self.numGhosts):
|
||||
noisyDistance = noisyDistances[ghostIndex]
|
||||
emissionModel = emissionModels[ghostIndex]
|
||||
if noisyDistance is None:
|
||||
if noisyDistances[ghostIndex] is None:
|
||||
# Ghost is in jail.
|
||||
particle = self.getParticleWithGhostInJail(particle, ghostIndex)
|
||||
else:
|
||||
# Find probability and update weight.
|
||||
ghostPosition = particle[ghostIndex]
|
||||
trueDistance = util.manhattanDistance(ghostPosition, pacmanPosition)
|
||||
probability = emissionModel[trueDistance]
|
||||
probability = emissionModels[ghostIndex][trueDistance]
|
||||
weight = weight * probability
|
||||
distribution.append(weight)
|
||||
samples.append(particle)
|
||||
@ -497,14 +496,17 @@ class JointParticleFilter:
|
||||
if not [p for p in distribution if p > 0.0]:
|
||||
# All probabilities are zero so we have to reinitialize.
|
||||
self.initializeParticles()
|
||||
newParticles = []
|
||||
# But then make sure that we move jailed ghosts into jail.
|
||||
for particle in self.particles:
|
||||
for ghostIndex in range(self.numGhosts):
|
||||
if noisyDistances[ghostIndex] is None:
|
||||
jailedGhostIndices = [i
|
||||
for i, noisyDistance in enumerate(noisyDistances)
|
||||
if noisyDistance is None]
|
||||
if jailedGhostIndices:
|
||||
newParticles = []
|
||||
for particle in self.particles:
|
||||
for ghostIndex in jailedGhostIndices:
|
||||
particle = self.getParticleWithGhostInJail(particle, ghostIndex)
|
||||
newParticles.append(particle)
|
||||
self.particles = newParticles
|
||||
newParticles.append(particle)
|
||||
self.particles = newParticles
|
||||
else:
|
||||
self.particles = util.nSample(distribution, samples, self.numParticles)
|
||||
|
||||
@ -563,12 +565,17 @@ class JointParticleFilter:
|
||||
"""
|
||||
newParticles = []
|
||||
for oldParticle in self.particles:
|
||||
prevGhostPositions = oldParticle
|
||||
newParticle = list(oldParticle) # A list of ghost positions
|
||||
# now loop through and update each entry in newParticle...
|
||||
|
||||
"*** YOUR CODE HERE ***"
|
||||
|
||||
"*** END YOUR CODE HERE ***"
|
||||
for ghostIndex in range(self.numGhosts):
|
||||
ghostPosition = newParticle[ghostIndex]
|
||||
newPosDist = getPositionDistributionForGhost(
|
||||
setGhostPositions(gameState, prevGhostPositions),
|
||||
ghostIndex,
|
||||
self.ghostAgents[ghostIndex])
|
||||
newPos = util.sample(newPosDist)
|
||||
newParticle[ghostIndex] = newPos
|
||||
newParticles.append(tuple(newParticle))
|
||||
self.particles = newParticles
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user