a=[(1,1,0),(1,2,1),(1,3,1)...]
這樣的一個串列 要往里面加x跟y不重復的資料,比如(1,1,1)就不往里加
寫if的時候能只比較xy么?
import numpy as np
import matplotlib.pyplot as plt
maze = np.loadtxt('maze.txt')
plt.imshow(maze,cmap='binary')
stack = []
seen = []
def dfs(maze,y,x):
stack = []
seen = []
stack.append((y,x))
while (len(stack)>0):
print("poen list =",stack)
print("close list =",seen)
(y,x) = stack.pop()
print("pop",(y,x),"\n")
seen.append((y,x))
for (next_y, next_x) in [(y+1, x), (y, x+1), (y, x-1), (y-1, x)]:
if maze[next_y][next_x] == 0 and (next_y, next_x) not in seen:
stack.append((next_y, next_x))
if (y,x) == (13,13):
break
dfs(maze,1,1)
這樣一個迷宮查找的程式 現在要改的按照路徑代價查找
給路徑賦值的話什么好的解決辦法么
大神們救救孩子
uj5u.com熱心網友回復:
沒看明白什么意思轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/41894.html
