classReflexAgent(Agent):"""
A reflex agent chooses an action at each choice point by examining
its alternatives via a state evaluation function.
The code below is provided as a guide. You are welcome to change
it in any way you see fit, so long as you don't touch our method
headers.
"""defgetAction(self, gameState):"""
You do not need to change this method, but you're welcome to.
getAction chooses among the best options according to the evaluation function.
Just like in the previous project, getAction takes a GameState and returns
some Directions.X for some X in the set {NORTH, SOUTH, WEST, EAST, STOP}
"""# Collect legal moves and successor states
legalMoves = gameState.getLegalActions()# Choose one of the best actions
scores =[self.evaluationFunction(gameState, action)for action in legalMoves]
bestScore =max(scores)
bestIndices =[index for index inrange(len(scores))if scores[index]== bestScore]
chosenIndex = random.choice(bestIndices)# Pick randomly among the best"Add more of your code here if you want to"return legalMoves[chosenIndex]defevaluationFunction(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 ***"# return Value [-1,1]
newFood = newFood.asList()
ghostPos =[(G.getPosition()[0], G.getPosition()[1])for G in newGhostStates]
scared =min(newScaredTimes)>0# if not new ScaredTimes new state is ghost: return lowest valueifnot scared and(newPos in ghostPos):return-1.0if newPos in currentGameState.getFood().asList():return1
closestFoodDist =sorted(newFood, key=lambda fDist: util.manhattanDistance(fDist, newPos))
cl
Question 1:Reflex Agentclass ReflexAgent(Agent): """ A reflex agent chooses an action at each choice point by examining its alternatives via a state evaluation function. The code below is provided as a guide. You are welcome to change