当前位置: 首页>>代码示例>>Python>>正文


Python Maze.bfs方法代码示例

本文整理汇总了Python中maze.Maze.bfs方法的典型用法代码示例。如果您正苦于以下问题:Python Maze.bfs方法的具体用法?Python Maze.bfs怎么用?Python Maze.bfs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在maze.Maze的用法示例。


在下文中一共展示了Maze.bfs方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: detect_maze

# 需要导入模块: from maze import Maze [as 别名]
# 或者: from maze.Maze import bfs [as 别名]
def detect_maze(vertex, width, height):
    """Try to detect maze with given maze size, starting at given vertex."""

    maze = Maze(width, height)
    dualmaze = Maze(width, height)

    last_vertex = vertex
    stack = [vertex]

    while len(stack) > 0:
        vertex = stack.pop()
        if is_done(vertex, maze, dualmaze): continue

        if vertex != last_vertex: run(maze.bfs(last_vertex, vertex), maze)
        last_vertex = detect_walls(vertex, maze, dualmaze)

        # Fill stack; avoid unnecessary paths
        stack.extend([v for v in maze.get_reachables(*vertex) if v != last_vertex and not is_done(v, maze, dualmaze)])
        if vertex != last_vertex: stack.append(last_vertex)

    return maze
开发者ID:flo7210,项目名称:WegfLaby_AP,代码行数:23,代码来源:main.py

示例2: int

# 需要导入模块: from maze import Maze [as 别名]
# 或者: from maze.Maze import bfs [as 别名]
        height = int(raw_input('Height: '))

        # Find nearest vertex to begin with
        start = estimate_current_vertex(width, height)
        m = detect_maze(start, width, height)
        print 'Maze detected!'

        name = raw_input('File name: ')
        with open(name, 'w') as f:
            f.write(repr(m))

        print 'String representation saved.'

    elif answer.upper() == 'B':
        name = raw_input('File name: ')
        with open(name, 'r') as f:
            s = f.read()
            m.parse(s)

        start = raw_input('Starting point (input format is "x,y"): ')
        finish = raw_input('Finish (input format is "x,y"): ')

        s = start.partition(',')
        f = finish.partition(',')

        a = (int(s[0]), int(s[2]))
        b = (int(f[0]), int(f[2]))

        path = m.bfs(a, b)
        run(path, m)
开发者ID:flo7210,项目名称:WegfLaby_AP,代码行数:32,代码来源:main.py


注:本文中的maze.Maze.bfs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。