Question: Cannot figure our what's wrong with this code but it won't stop running when I run it. This is python code for a pac-man game

Cannot figure our what's wrong with this code but it won't stop running when I run it. This is python code for a pac-man game to find the corners of the maze

def cornersHeuristic(state, problem): """ A heuristic for the CornersProblem that you defined.

state: The current search state (a data structure you chose in your search problem)

problem: The CornersProblem instance for this layout.

This function should always return a number that is a lower bound on the shortest path from the state to a goal of the problem; i.e. it should be admissible (as well as consistent). """ corners = problem.corners # These are the corner coordinates walls = problem.walls # These are the walls of the maze, as a Grid (game.py)

"*** YOUR CODE HERE ***" currPos = state[0] if problem.isGoalState(state): return 0 # find the shortest path uncheckedCor = list(state[1][:]) path = 0; # print(uncheckedCor[0]) while len(uncheckedCor) > 0: closetPos = closetCorner(currPos,uncheckedCor) path += util.manhattanDistance(currPos,closetPos) currPos = closetPos uncheckedCor.remove(closetPos) uncheckedCor = tuple(uncheckedCor) return path def closetCorner(start, cor): if len(cor) == 0: return None closetCorner = cor[0] shortestPath = util.manhattanDistance(start,cor[0]) for pos in cor[1:4]: cost = util.manhattanDistance(start,pos) if cost < shortestPath: shortestPath = cost closetCorner = pos return closetCorner

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!