本文整理汇总了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
示例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)