Skip to content

Instantly share code, notes, and snippets.

@rioleo
Created October 18, 2011 18:44
Show Gist options
  • Save rioleo/1296286 to your computer and use it in GitHub Desktop.
Save rioleo/1296286 to your computer and use it in GitHub Desktop.
Q3
# Add this to the chooseAction in bustersAgent
pacmanPosition = gameState.getPacmanPosition()
legal = [a for a in gameState.getLegalPacmanActions()]
livingGhosts = gameState.getLivingGhosts()
livingGhostPositionDistributions = [beliefs for i,beliefs
in enumerate(self.ghostBeliefs)
if livingGhosts[i+1]]
likelyghostPosition = max(livingGhostPositionDistributions[0].iteritems(), key=operator.itemgetter(1))[0]
minDist = 999
for action in legal:
vector = Actions.directionToVector( action, 1 )
# Reference: http://stackoverflow.com/questions/497885/python-tuple-operations
distanceToGhost = self.distancer.getDistance(tuple(map(operator.add, vector, pacmanPosition)), likelyghostPosition)
if distanceToGhost < minDist:
minDist = distanceToGhost
chooseAction = action
return chooseAction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment