-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample30.py
51 lines (48 loc) · 1.34 KB
/
example30.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
maze1 = [
[0, 1, 1, 1, 0, 0, 0, 1],
[0, 0, 0, 1, 0, 1, 0, 1],
[1, 1, 0, 1, 0, 1, 0, 0],
[1, 1, 0, 1, 0, 0, 1, 0],
[1, 0, 0, 0, 1, 0, 1, 0],
[0, 0, 1, 0, 1, 0, 1, 0],
[0, 1, 1, 0, 0, 0, 1, 0],
[0, 0, 0, 0, 1, 0, 1, 0],
]
def next_step(konum, maze):
komsu_list = [
(konum[0] + 1, konum[1]),
(konum[0], konum[1] + 1),
(konum[0], konum[1] - 1),
(konum[0] - 1, konum[1])
]
aday = []
for i in komsu_list:
try:
if maze[i[0]][i[1]] == 0:
aday.append(i)
except IndexError:
pass
return aday
def run(konum, son, maze, path=[], crossover=[], count=0):
path.append(konum)
# print(konum)
# print(crossover)
# print(np.array(maze))
maze[konum[0]][konum[1]] = 1
if konum == son:
return True, path
elif next_step(konum, maze) == []:
if crossover == []:
return False, path
else:
sonraki = crossover[0]
crossover = crossover[1:]
return run(sonraki, son, maze, path, crossover)
else:
count += 1
sonraki = next_step(konum, maze)[0]
kalanlar = next_step(konum, maze)[1:]
if kalanlar != []:
crossover += kalanlar
return run(sonraki, son, maze, path, crossover)
print(run((0, 0), (7, 7), maze1))