I've been working on Berkeley's Pacman project for their A.I. course. I'm running into an issue figuring out how to find a path so that pacman touches all four corners of the pacman board. It uses a general breadth-first search algorithm. It only returns a path when there is one goal state, and not four.
The project for this particular question states:
In corner mazes, there are four dots, one in each corner. Our new search problem is to find the shortest path through the maze that touches all four corners (whether the maze actually has food there or not). Note that for some mazes like tinyCorners, the shortest path does not always go to the closest food first! Hint: the shortest path through tinyCorners takes 28 steps.
Implement the CornersProblem search problem in searchAgents.py. You will need to choose a state representation that encodes all the information necessary to detect whether all four corners have been reached.
BFS:
fringe = util.Queue()
fringe.push( (problem.getStartState(), [], 0) )
visited = set()
while not fringe.isEmpty():
curState, curAction, curCost = fringe.pop()
if curState in visited:
continue
visited.add(curState)
if problem.isGoalState(curState):
return curAction
for state, action, cost in problem.getSuccessors(curState):
fringe.push( (state, curAction + [action], cost ) )
return []
util.raiseNotDefined()
Search Agent Start State:
def getStartState(self):
"""
Returns the start state (in your state space, not the full Pacman state
space)
"""
"*** YOUR CODE HERE ***"
return self.startingPosition
util.raiseNotDefined()
SearchAgent Goal State
"""
Returns whether this search state is a goal state of the problem.
"""
"*** YOUR CODE HERE ***"
// TODO
util.raiseNotDefined()
I'm stuck on the returning the goal state so that the test passes. Currently, the function returns:
*** FAIL: test_cases/q5/corner_tiny_corner.test
*** Corners missed: [(1, 1), (1, 6), (6, 1), (6, 6)]
*** Tests failed.
Or I return only 1 out of the 4 corners.