searchAgents.py 文件源码

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

项目:cs188_tbf 作者: loren-jiang 项目源码 文件源码
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)
    #3) manhattan dist to closest + manhattan to the unvisited others , gives: total cost of 106,  nodes expanded: 692
    pos = state[0]
    unvisited = list(state[1])
    ret = 0

    while len(unvisited) > 0:
        nextPos = closestCorner(pos, unvisited)
        ret += manhattanDistance(pos, nextPos)
        pos = nextPos
        unvisited.remove(nextPos)
    return ret
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号