小编mat*_*317的帖子

Python迷宫生成器说明

欢迎.有人能解释一下这段代码会发生什么吗?我想知道这是如何工作的(它来自http://rosettacode.org/wiki/Maze_generation#Python).

from random import shuffle, randrange
def make_maze(w = 16, h = 8):
    vis = [[0] * w + [1] for _ in range(h)] + [[1] * (w + 1)]
    ver = [["|  "] * w + ['|'] for _ in range(h)] + [[]]
    hor = [["+--"] * w + ['+'] for _ in range(h + 1)]

    def walk(x, y):
        vis[y][x] = 1

        d = [(x - 1, y), (x, y + 1), (x + 1, y), (x, …
Run Code Online (Sandbox Code Playgroud)

python maze depth-first-search

5
推荐指数
1
解决办法
4936
查看次数

标签 统计

depth-first-search ×1

maze ×1

python ×1