穿过迷宫的最短路径
我正在开发一个项目,我必须使用左手法则遍历迷宫,并根据程序遇到的交叉点,我需要创建一个节点来连接到一个图,然后我将确定最短路径。目标是让程序运行穿过迷宫,然后关闭程序并从包含图形的文件中读取并确定到达终点的最短路径。我所做的是我可以使用左手法则穿过迷宫。我想做的是,当我找到交叉点时创建一个节点,每次程序移动时,我都会将该路径的成本增加一。顺便说一句,使用 dijkstra 算法时是否需要邻接矩阵?
I am working on a project that i must traverse a maze using the left-hand rule and based upon the intersections the program comes upon i need to create a node to connect to a graph that I will then determine the shortest path. The goal is for the program to run through the maze then close out the program and read from a file that contains the graph and determines the shortest path to the finish. what i have done is i can traverse the maze using the left-hand rule. what im thinking to do is create a node when i find the intersection and there after every time the program moves i increase the cost of that path by one. on a side note do you need to have an adjacency matrix when use dijkstra's algorithm?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试这样的操作,它应该可以工作:
当您检查堆栈顶部的当前位置时,您可能需要检查最后一个元素之前的元素,因为最后一个元素将是您刚刚离开的位置。
Try something like this, it should work:
When you're checking the top of the stack for the current position, you might need to check the element just before the very last one, since the last one will be the position you just left.