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]
- if successorGameState.isWin():
- return 1000
- res = successorGameState.getScore()
- if len(successorGameState.getFood().asList()) < len(currentGameState.getFood().asList()):
- res +=200
- else:
- old = getMin(currentGameState)
- new = getMin(successorGameState)
- m = min(new, old)
- res -= 50*m
- # if new < old :
- # res-= 50*new
- # else: res -= 50*old
- for gh in newGhostStates:
- dis = manhattanDistance(newPos, gh.getPosition())
- if dis == 1: return -1000
- if manhattanDistance(newPos, gh.getPosition())< 5:
- res -= 100*manhattanDistance(newPos, gh.getPosition())
- return res
- def getMin(pos):
- m = 99999
- curr = pos.getPacmanPosition()
- for f in pos.getFood().asList():
- m = min(m, manhattanDistance(curr, f))
- return m
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement