Advertisement
Guest User

Untitled

a guest
Oct 17th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. def evaluationFunction(self, currentGameState, action):
  2. """
  3. Design a better evaluation function here.
  4.  
  5. The evaluation function takes in the current and proposed successor
  6. GameStates (pacman.py) and returns a number, where higher numbers are better.
  7.  
  8. The code below extracts some useful information from the state, like the
  9. remaining food (newFood) and Pacman position after moving (newPos).
  10. newScaredTimes holds the number of moves that each ghost will remain
  11. scared because of Pacman having eaten a power pellet.
  12.  
  13. Print out these variables to see what you're getting, then combine them
  14. to create a masterful evaluation function.
  15. """
  16. # Useful information you can extract from a GameState (pacman.py)
  17. successorGameState = currentGameState.generatePacmanSuccessor(action)
  18. newPos = successorGameState.getPacmanPosition()
  19. newFood = successorGameState.getFood()
  20. newGhostStates = successorGameState.getGhostStates()
  21. newScaredTimes = [ghostState.scaredTimer for ghostState in newGhostStates]
  22.  
  23.  
  24. "*** YOUR CODE HERE ***"
  25.  
  26. score = successorGameState.getScore()
  27.  
  28.  
  29. gDist = 100000000
  30. k = len (newGhostStates)
  31.  
  32. for gh in newGhostStates:
  33. ghostPosition = gh.configuration.pos
  34. d = manhattanDistance( ghostPosition, newPos)
  35. if d < gDist:
  36. gDist = d
  37. if d <= 1.0:
  38. score-=3
  39.  
  40.  
  41. n = len (newGhostStates)
  42. fDist = n * 100000
  43.  
  44. for fo in newFood.asList():
  45. d = manhattanDistance( fo, newPos)
  46. fDists +=d
  47.  
  48. if d < fDist and d > 0:
  49. fDist = d
  50.  
  51. if(fDist == 0):
  52. score +=2
  53. else:
  54. score+= 1.5/fDist
  55.  
  56. return score
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement