Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def evaluationFunction(self, currentGameState, action):
- """
- Design a better evaluation function here.
- The evaluation function takes in the current and proposed successor
- GameStates (pacman.py) and returns a number, where higher numbers are better.
- The code below extracts some useful information from the state, like the
- remaining food (newFood) and Pacman position after moving (newPos).
- newScaredTimes holds the number of moves that each ghost will remain
- scared because of Pacman having eaten a power pellet.
- Print out these variables to see what you're getting, then combine them
- to create a masterful evaluation function.
- """
- # Useful information you can extract from a GameState (pacman.py)
- successorGameState = currentGameState.generatePacmanSuccessor(action)
- newPos = successorGameState.getPacmanPosition()
- newFood = successorGameState.getFood()
- newGhostStates = successorGameState.getGhostStates()
- newScaredTimes = [ghostState.scaredTimer for ghostState in newGhostStates]
- "*** YOUR CODE HERE ***"
- score = successorGameState.getScore()
- gDist = 100000000
- k = len (newGhostStates)
- for gh in newGhostStates:
- ghostPosition = gh.configuration.pos
- d = manhattanDistance( ghostPosition, newPos)
- if d < gDist:
- gDist = d
- if d <= 1.0:
- score-=3
- n = len (newGhostStates)
- fDist = n * 100000
- for fo in newFood.asList():
- d = manhattanDistance( fo, newPos)
- fDists +=d
- if d < fDist and d > 0:
- fDist = d
- if(fDist == 0):
- score +=2
- else:
- score+= 1.5/fDist
- return score
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement