Beispiel #1
0
	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]
		newScore = successorGameState.getScore()

		if successorGameState.isLose():
			return newScore-1000
		if successorGameState.isWin():
			return newScore+1000

		if(max(newScaredTimes)==40):
			newScore = newScore + 40 #Weigh scores here we score a super pellet highly

		for i in range(len(newGhostStates)):
			ghost = newGhostStates[i]

			#ignore ghosts you can eat
			if(ghost.scaredTimer!=0):
				continue

			i = i+1
			newScore = newScore + ghost.scaredTimer

			# Check if the ghost can move into our square in the next turn
			for ghostAction in GhostRules.getLegalActions(successorGameState, i):
				ghostSuccessor = successorGameState.generateSuccessor(i, ghostAction)
				if ghostSuccessor.getGhostState(i).getPosition() == newPos:
					return newScore-1000

		if(len(currentGameState.getFoodCoords())==len(successorGameState.getFoodCoords())):
			newScore = newScore - successorGameState.getClosestFood(newPos)[2]

		return newScore
Beispiel #2
0
def betterEvaluationFunction(currentGameState):
	"""
	  Your extreme ghost-hunting, pellet-nabbing, food-gobbling, unstoppable
	  evaluation function (question 5).

	  DESCRIPTION: <write something here so we know what you did>
	"""
	# Useful information you can extract from a GameState (pacman.py)
	newPos = currentGameState.getPacmanPosition()
	newFood = currentGameState.getFood()
	newGhostStates = currentGameState.getGhostStates()
	newScaredTimes = [ghostState.scaredTimer for ghostState in newGhostStates]
	newScore = currentGameState.getScore()*200

	if currentGameState.isLose():
		return newScore-1000
	if currentGameState.isWin():
		return newScore+1000

	#if(max(newScaredTimes)==40):
	newScore = newScore + max(newScaredTimes)*1000 #Weigh scores here we score a super pellet highly

	ghostDistance = 0
	for i in range(len(newGhostStates)):
		ghost = newGhostStates[i]

		#ignore ghosts you can eat
		if(ghost.scaredTimer!=0):
			ghostDistance -= manhattanDistance(ghost.getPosition(), newPos);
			continue

		i = i+1
		newScore = newScore + ghost.scaredTimer
		if(manhattanDistance(ghost.getPosition(), newPos) < 10):
			ghostDistance += manhattanDistance(ghost.getPosition(), newPos);

		# Check if the ghost can move into our square in the next turn
		for ghostAction in GhostRules.getLegalActions(currentGameState, i):
			ghostSuccessor = currentGameState.generateSuccessor(i, ghostAction)
			if ghostSuccessor.getGhostState(i).getPosition() == newPos:
				return newScore-1000

	# if(len(currentGameState.getFoodCoords())==len(currentGameState.getFoodCoords())):
	newScore = newScore - currentGameState.getClosestFood(newPos)[2]
	#newScore += ghostDistance/100;

	return newScore