searchAgents.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:Berkeley-AI-PacMan-Lab-1 作者: jrios6 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号