def getSuccessors(self, currentState):
"""
Returns successor states, the actions they require, and a cost of 1.
As noted in search.py:
For a given state, this should return a list of triples,
(successor, action, stepCost), where 'successor' is a
successor to the current state, 'action' is the action
required to get there, and 'stepCost' is the incremental
cost of expanding to that successor
"""
successors = []
for action in [Directions.NORTH, Directions.SOUTH, Directions.EAST, Directions.WEST]:
x,y = currentState[0]
dx, dy = Actions.directionToVector(action)
nextx, nexty = int(x + dx), int(y + dy)
if not self.walls[nextx][nexty]:
#Copies corner visited by node previously to nextState
nextState = [(nextx, nexty), currentState[1][:]]
if nextState[0] in self.corners and nextState[0] not in nextState[1]:
#Add current corner state visited to nextState node
nextState[1].append(nextState[0])
successors.append( ( nextState, action, 1) )
# Bookkeeping for display purposes
self._expanded += 1
return successors
评论列表
文章目录