project2_multiagent/multiagent/multiAgents.py
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()
        #print("new_food:", newFood)
        newGhostStates = successorGameState.getGhostStates()
        newScaredTimes = [ghostState.scaredTimer for ghostState in newGhostStates]

        "*** YOUR CODE HERE ***"
        newFood = newFood.asList()#list
        ghostPos = []
        for G in newGhostStates:
            ghostPos_ = G.getPosition()[0], G. getPosition()[1]
            ghostPos.append(ghostPos_)
        #ghostPos = [(G.getPosition()[0], G.getPosition()[1]) for G in newGhostStates]
        scared = newScaredTimes[0] > 0
        # if not new ScaredTimes new state is ghost: return lowest value
        if not scared and (newPos in ghostPos):
            return -1.0

        if newPos in currentGameState.getFood().asList():
            return 1

        closestFoodDist = sorted(newFood, key=lambda fDist: util.manhattanDistance(fDist, newPos))
        closestGhostDist = sorted(ghostPos, key=lambda gDist: util.manhattanDistance(gDist, newPos))

        fd = lambda fDis: util.manhattanDistance(fDis, newPos)

        gd = lambda gDis: util.manhattanDistance(gDis, newPos)

        return 1 / fd(closestFoodDist[0]) - 1/gd(closestGhostDist[0])
        "*** YOUR CODE HERE ***"

        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.
        
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.
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 .
def evaluationFunction(self, currentGameState, action):
        successorGameState = currentGameState.generatePacmanSuccessor(action)
        newPos = successorGameState.getPacmanPosition()
        newFood = successorGameState.getFood()
        newGhostStates = successorGameState.getGhostStates()
        newScaredTimes = [ghostState.scaredTimer for ghostState in newGhostStates]
        newFood = newFood.asList()
        ghostPos = []
        for G in newGhostStates:
            ghostPos_ = G.getPosition()[0], G. getPosition()[1]
            ghostPos.append(ghostPos_)
        scared = newScaredTimes[0] > 0
        if not scared and (newPos in ghostPos):
            return -1.0
        if newPos in currentGameState.getFood().asList():
            return 1
        closestFoodDist = sorted(newFood, key=lambda fDist: util.manhattanDistance(fDist, newPos))
        closestGhostDist = sorted(ghostPos, key=lambda gDist: util.manhattanDistance(gDist, newPos))
        fd = lambda fDis: util.manhattanDistance(fDis, newPos)
        gd = lambda gDis: util.manhattanDistance(gDis, newPos)
        return 1 / fd(closestFoodDist[0]) - 1/gd(closestGhostDist[0])
def evaluationFunction ( self , currentGameState , action ) : successorGameState = currentGameState . generatePacmanSuccessor ( action ) newPos = successorGameState . getPacmanPosition ( ) newFood = successorGameState . getFood ( ) newGhostStates = successorGameState . getGhostStates ( ) newScaredTimes = [ ghostState . scaredTimer for ghostState in newGhostStates ] "*** YOUR CODE HERE ***" newFood = newFood . asList ( ) ghostPos = [ ] for G in newGhostStates : ghostPos_ = G . getPosition ( ) [ 0 ] , G . getPosition ( ) [ 1 ] ghostPos . append ( ghostPos_ ) scared = newScaredTimes [ 0 ] > 0 if not scared and ( newPos in ghostPos ) : return - 1.0 if newPos in currentGameState . getFood ( ) . asList ( ) : return 1 closestFoodDist = sorted ( newFood , key = lambda fDist : util . manhattanDistance ( fDist , newPos ) ) closestGhostDist = sorted ( ghostPos , key = lambda gDist : util . manhattanDistance ( gDist , newPos ) ) fd = lambda fDis : util . manhattanDistance ( fDis , newPos ) gd = lambda gDis : util . manhattanDistance ( gDis , newPos ) return 1 / fd ( closestFoodDist [ 0 ] ) - 1 / gd ( closestGhostDist [ 0 ] ) "*** YOUR CODE HERE ***"
Design a better evaluation function here.
Design a better evaluation function here .
"""
        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) #print("new_food:", newFood) "*** YOUR CODE HERE ***" #list #ghostPos = [(G.getPosition()[0], G.getPosition()[1]) for G in newGhostStates] # if not new ScaredTimes new state is ghost: return lowest value "*** YOUR CODE HERE ***"
self
currentGameState
action