在我之后,在一些帮助下,让我的import_maze函数正常工作我遇到了maze_solving函数的问题,经过2个小时的实验后,除了再次寻求帮助之外我没有其他选择。所以我的maze_solving函数抛出以下错误:
C:\Python34\python.exe C:/Users/Anton/PycharmProjects/BWINF_Aufgabe_1/Wegfinden.py
Traceback (most recent call last):
File "C:/Users/Anton/PycharmProjects/BWINF_Aufgabe_1/Wegfinden.py", line 65, in <module>
solved, solution = maze_solve(startx, starty, maze, solution)
File "C:/Users/Anton/PycharmProjects/BWINF_Aufgabe_1/Wegfinden.py", line 44, in maze_solve
solved, temp = maze_solve(x-1, y, maze, solution)
File "C:/Users/Anton/PycharmProjects/BWINF_Aufgabe_1/Wegfinden.py", line 34, in maze_solve
solved, temp = maze_solve(x+1, y, maze, solution)
File "C:/Users/Anton/PycharmProjects/BWINF_Aufgabe_1/Wegfinden.py", line 34, in maze_solve
solved, temp = maze_solve(x+1, y, maze, solution)
File "C:/Users/Anton/PycharmProjects/BWINF_Aufgabe_1/Wegfinden.py", line 27, in maze_solve
if maze[x][y] == "#" or maze[x][y] == "*":
RuntimeError: maximum recursion depth exceeded in comparison
Process finished with exit code 1
我的代码:http://hastebin.com/owugupicaz.py
迷宫:
6 9
#########
# # #
# # # #
# K # #
# # #
#########
答案 0 :(得分:1)
您正在陷入无限递归,因为您正在处理已被标记为潜在路径的路径。这是因为您不会在重复之前标记您的路径。而不是在检查中标记路径以求解决,而是将maze[x][y]="*"
放在递归和解决方案检查之外。如果您将错误路径设置为" "
,那么自然只有好路径会保留标记