使用 bfs 和 dfs 解决迷宫

问题描述 投票:0回答:1

如何将下图中的迷宫转换为矩阵 Follwing is the image of the maze

我尝试使用#作为墙壁,使用p作为从起点开始的路径,但我无法构建完美的矩阵,并使用dfs,bfs来解决迷宫

search graph-theory depth-first-search breadth-first-search maze
1个回答
0
投票

你没有提到你想要什么编码语言。

这是用 C++ 编写的解决方案

https://github.com/JamesBremner/PathFinder/blob/main/src/cMaze.cpp

文档

https://github.com/JamesBremner/PathFinder/wiki/Maze

我无法建立一个完美的矩阵

猜测你的意思是邻接矩阵。除非你的迷宫非常小(<= 10 by 10 ) you will be better off with adjacency lists, which use up less memory.

© www.soinside.com 2019 - 2024. All rights reserved.