Advertisement
Guest User

Untitled

a guest
Oct 6th, 2015
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 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. if successorGameState.isWin():
  23. return 1000
  24. res = successorGameState.getScore()
  25. if len(successorGameState.getFood().asList()) < len(currentGameState.getFood().asList()):
  26. res +=200
  27. else:
  28. old = getMin(currentGameState)
  29. new = getMin(successorGameState)
  30. m = min(new, old)
  31. res -= 50*m
  32. # if new < old :
  33. # res-= 50*new
  34. # else: res -= 50*old
  35. for gh in newGhostStates:
  36. dis = manhattanDistance(newPos, gh.getPosition())
  37. if dis == 1: return -1000
  38. if manhattanDistance(newPos, gh.getPosition())< 5:
  39. res -= 100*manhattanDistance(newPos, gh.getPosition())
  40.  
  41. return res
  42.  
  43. def getMin(pos):
  44. m = 99999
  45. curr = pos.getPacmanPosition()
  46. for f in pos.getFood().asList():
  47. m = min(m, manhattanDistance(curr, f))
  48. return m
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement