简体   繁体   English

C ++ DFS中的迷宫回溯算法?

[英]Maze Backtracking Algorithm in C++ DFS?

I am new to C++ and I am currently on a project to create a maze that generates out using the DFS algorithm. 我是C ++的新手,目前在一个创建使用DFS算法生成的迷宫的项目中。

I've already successfully managed to generate out a single path, which is for example 我已经成功地设法生成了一条路径,例如

0 , 0 , 0 , 0,  0
0 , 1 , 1 , S,  0
0 , 1 , 0 , 0,  0
0 , 1 , 0 , 0,  0
0 , D , 0 , 0,  0
0 , 0 , 0 , 0,  0

As above, 如上,

Source is the initial cell, and 1 is the path that I created based on random neighbor, the thing is, D is "dead end". Source是初始单元格,1是我基于随机邻居创建的路径,事实是D是“死角”。 So, if possible I will like to backtrack to S and start from the other direction. 因此,如果可能的话,我想回溯到S并从另一个方向开始。 How am I supposed to do that with queue and stack? 我应该如何使用队列和堆栈来做到这一点? Can anyone shed some light on this? 谁能对此有所启发? Thank you so much? 非常感谢?

It's better if we used basic AI knowledge. 如果我们使用基本的AI知识会更好。 Define a set of valid operations for this specific problem, an initial state, a final state and let your program use a search tree of states with the defined operations to find the solution. 定义针对此特定问题的一组有效操作,即初始状态,最终状态,并让您的程序使用search tree of states与已定义的操作来查找解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM