```python
"""
迷宫问题1:
有如下迷宫,给定起始位置,和出口位置,怎么走出去?
"""
mat = [
[0,0,0,0,0,0,0,0],
[0,1,1,1,1,0,1,0],
[0,0,0,0,1,0,1,0],
[0,1,0,0,0,0,1,0],
[0,1,0,1,1,0,1,0],
[0,1,0,0,0,0,1,1],
[0,1,0,0,1,0,0,0],
[0,1,1,1,1,1,1,0]
]
start = [0,0]
end = [7,7]
def wrapped(mat):
new_mat = [[1 for i in range(len(mat[0])+2)] for j in range(len(mat)+2)]
for i in range(len(mat)):
new_mat[i+1][1:-1] = mat[i]
return new_mat
print(wrapped(mat))
new_mat = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 1, 1, 1, 1, 0, 1, 0, 1],
[1, 0, 0, 0, 0, 1, 0, 1, 0, 1],
[1, 0, 1, 0, 0, 0, 0, 1, 0, 1],
[1, 0, 1, 0, 1, 1, 0, 1, 0, 1],
[1, 0, 1, 0, 0, 0, 0, 1, 1, 1],
[1, 0, 1, 0, 0, 1, 0, 0, 0, 1],
[1, 0, 1, 1, 1, 1, 1, 1, 0, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]
new_start = [1,1,-1]
new_end = [8,8]
queue = [new_start]
# color
new_mat[new_start[0]][new_start[1]] = 1
trace = []
while queue:
now_point = queue.pop(0)
trace.append(now_point)
if now_point[0] == new_end[0] and now_point[1] == new_end[1]:
print("ok")
break
# up
if new_mat[now_point[0]-1][now_point[1]] == 0:
queue.append([now_point[0]-1, now_point[1], [now_point[0], now_point[1]]])
new_mat[now_point[0]-1][now_point[1]] = 1
# down
if new_mat[now_point[0]+1][now_point[1]] == 0:
queue.append([now_point[0]+1, now_point[1], [now_point[0], now_point[1]]])
new_mat[now_point[0]+1][now_point[1]] = 1
# left
if new_mat[now_point[0]][now_point[1]-1] == 0:
queue.append([now_point[0], now_point[1] -1, [now_point[0], now_point[1]]])
new_mat[now_point[0] + 1][now_point[1] -1] = 1
# right
if new_mat[now_point[0]][now_point[1] + 1] == 0:
queue.append([now_point[0], now_point[1] + 1, [now_point[0], now_point[1]]])
new_mat[now_point[0]][now_point[1] + 1] = 1
print(trace)
route = {}
for i in trace:
route[(i[0], i[1])] = i[2]
print(route)
rst = [new_end]
while True:
p = route.get((rst[-1][0], rst[-1][1]))
rst.append(p)
if p == new_start[:2]:
print("+++++++++++")
break
print(rst)