def getSuccessors(self, state): """ 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 = [] # print "getSucc: state at beginning: ", state for action in [Directions.NORTH, Directions.SOUTH, Directions.EAST, Directions.WEST]: # Add a successor state to the successor list if the action is legal # Here's a code snippet for figuring out whether a new position hits a wall x,y = state[0] dx, dy = Actions.directionToVector(action) nextx, nexty = int(x + dx), int(y + dy) hitsWall = self.walls[nextx][nexty] if not hitsWall: nextState = search.cornerState((nextx, nexty), checkCorners((nextx,nexty),state[1])) # print "nextState: ", nextState.corners # nextState = (nextx,nexty) cost = 1 successors.append( (nextState, action, cost) ) self._expanded += 1 return successors
def noWallSuccessors(state): successors = [] for action in [Directions.NORTH, Directions.SOUTH, Directions.EAST, Directions.WEST]: x,y = state.loc dx, dy = Actions.directionToVector(action) nextx, nexty = int(x + dx), int(y + dy) # if not walls[nextx][nexty]: nextState = search.cornerState((nextx, nexty), checkCorners((nextx,nexty),state[1])) cost = 1 successors.append( ( nextState, action, cost) ) return successors
def getStartState(self): "Returns the start state (in your state space, not the full Pacman state space)" "*** YOUR CODE HERE ***" return search.cornerState(self.startingPosition, self.corners)