-
Notifications
You must be signed in to change notification settings - Fork 1
/
maze_vision.py
108 lines (88 loc) · 2.35 KB
/
maze_vision.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# 0 = open space, 1=boundary , 2= the robot, 3= finish
def maze_vision():
path= ''
maze=[]
maze.append(list('000000002000000'))
maze.append(list('000000003001100'))
maze.append(list('000000000000000'))
maze.append(list('000000000000000'))
maze.append(list('000000000000000'))
maze.append(list('000000000000000'))
#print(maze)
fx=0
fy=0
sx=0
sy=0
#print(maze[0][8])
#print(len(maze[0]))
for x in range(0,len(maze[0])-1):
for y in range(0,len(maze)-1):
if maze[y][x]=='2':
sx=x
sy=y
elif maze[y][x]=='3':
fx=x
fy=y
#print(fx)
#print(fy)
#print(sx)
#print(sy)
ans= distance(maze,sx,sy,fx,fy,path)
print ("the shortest path is "+str(ans)+ " spaces")
print(path)
def distance(maze, sx, sy, fx, fy,path):
up= int(sy-1)
down= int(sy+1)
left = int(sx-1)
right = int(sx+1)
print(str(sx)+','+str(sy))
updist=3333333
downdist=6666666
leftdist=5555555
rightdist=4444444
if maze[sy][sx]=='3': #reached finish
print(hit)
return 0 #return
#up
# if up >-1:
# if maze[sy][up]=='0': #if this direction is open
# maze[sy][up]='4' #mark it as traveled to
# path= path +'u' #add that direction to final path
# updist= 1+ distance(maze,up,sy,fx,fy,path) #calculate shortest dist from there
#if it makes it past here, that was not the shortest distance
#path= path[:-1] #remove that direction from final path
#maze[sy][up]=0 #mark that direction as not traveled
#down
print(down)
if down < (len(maze)-1):
print('w')
print(maze[down][sx])
if maze[down][sx]=='0':
maze[sy][sx]='4'
#path path +'d'
downdist= 1 + distance(maze,down,sy,fx,fy,path)
#path= path[:-1]
#maze[sy][down]='0'
#else:
#downdist=999999
#left
# if left>-1:
# if maze[left][sx]=='0':
# maze[left][sx]='4'
# path= path +'l'
# leftdist= 1+distance(maze,sx,left,fx,fy,path)
# path= path[:-1]
# maze[left][sx]='0'
#right
# if right<(len(maze[0])-1):
# if maze[sx][right]=='0':
# maze[sx][right]='4'
# path=path+'r'
# rightdist= 1+distance(maze,sx,right,fx,fy,path)
# path=path[:-1]
# maze[right][sx]='0'
#print(str(sx)+','+str(sy))
return min(updist,downdist,rightdist,leftdist)
# sum2= min(rightdist,leftdist)
# return min(sum2,sum1)
maze_vision()