gpt4 book ai didi

graph - 如何将迷宫转换为图形?

转载 作者:行者123 更新时间:2023-12-04 02:18:01 28 4
gpt4 key购买 nike

我正在尝试将迷宫数据结构转换为图形。迷宫就像一个网格和一些细胞之间的墙壁。

maze[8][8][4] is how the maze is represented.
If maze[i][j][0] = 1 it means you can't go up from (i,j)
if maze[i][j][1] = 1 it means you can't go down from (i,j)
// and so on

我想把这个迷宫转换成图形,我该怎么做?

最佳答案

您可以通过两种方式做到这一点:

1.从您的初始矩阵创建一个邻接矩阵。邻接矩阵的形式为:

h[i][j] = 0, if there is no direct link from i to j 
(i and j are not neighbors in the maze)
h[i][j] = 1, if there is a direct link from i to j
(i and j are neighbors in the maze)


2.为每个节点创建邻居列表: ji的邻居列表中如果 i之间有直接联系和 j .

关于graph - 如何将迷宫转换为图形?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10666054/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com