-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolvability_algorithm.py
63 lines (46 loc) · 1.35 KB
/
solvability_algorithm.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
import queue
from train_GAN_4_fl import *
def is_f(maze, row, column, tile):
return maze[4 * column + 31 * 4 * row + tile] == 1
def data(row, column):
return 30 - row + 29 - column, (row, column)
def neighbour(x, y):
neighbours = []
if x != 0:
neighbours.append((x-1, y))
if x != 30:
neighbours.append((x+1, y))
if y != 0:
neighbours.append((x, y-1))
if y != 30:
neighbours.append((x, y+1))
return neighbours
def solvable(maze):
open_set = queue.PriorityQueue()
open_set.put(data(0, 1))
if not is_f(maze, 0, 1, 2):
return False
closed_set = []
while not open_set.empty():
position = open_set.get()[1]
closed_set.append(position)
neighbours = neighbour(position[0], position[1])
for pos in neighbours:
if is_f(maze, pos[0], pos[1], 0) and pos not in closed_set:
open_set.put(data(pos[0], pos[1]))
elif is_f(maze, pos[0], pos[1], 3) and pos == (30, 29):
return True
return False
if __name__=='__main__':
dataset = MyDataset('levels_corrected.csv')
loader = DataLoader(
dataset,
batch_size=40,
shuffle=True,
num_workers=2
)
for d in loader:
break
#print(d[0])
maze = d[0]
print("maze solvable: ", solvable(maze))