在BFS中跟踪节点-Python,迷宫

时间:2020-02-17 05:22:53

标签: python numpy nodes breadth-first-search

我正在Python 3.7.3中由2D numpy数组表示的迷宫中实现BFS。这段代码生成迷宫:

for row in range(dim):
        # Add an empty array that will hold each cell
        # in this row
        grid.append([])
        for column in range(dim):
            grid[row].append(np.random.binomial(1, 0.2, 1))  # Append a cell
            if (row == column == dim - 1):
                grid[row][column] = 0
        grid[0][0] = 0

我想避免使用节点类,因为我在节点类上取得的成功有限。我想知道如何在BFS搜索中从这个迷宫的(0,0)位置到(尺寸-1,尺寸-1)位置来表示/存储父子关系。同样,鉴于图/迷宫/网格的性质,我需要避免让孩子拥有相同位置但父母不同的孩子。我想返回起点和终点之间的最短节点列表。

感谢您的帮助。

0 个答案:

没有答案
相关问题