-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmazeDebug.py
More file actions
190 lines (160 loc) · 6.64 KB
/
mazeDebug.py
File metadata and controls
190 lines (160 loc) · 6.64 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import readline
def printMaze(maze):
writeTxt = open("solution.txt", "w")
writeTxt.close()
writeTxt = open("solution.txt", "a")
for i in range(len(maze)):
for k in range(len(maze[len(maze) - i - 1])):
writeTxt.write(maze[len(maze) - i - 1][k])
writeTxt.write("\n")
writeTxt.close()
filePath = "" #enter file path of homework txts here
mazeID = input("MazeID: ")
mazeFile = "maze_"+ mazeID +".txt"
startx = input("Start x: ")
starty = input("Start y: ")
endx = input("End x: ")
endy = input("End y: ")
mazeSolution = "maze_1_path_" + startx + "_" + starty + "_" + endx + "_" + endy + ".txt"
inputMazeFile = open(filePath+mazeFile)
inputSolutionFile = open(filePath+mazeSolution)
mazeLine1 = inputMazeFile.readline()
mazeLine1 = mazeLine1.split(" ")
mazeRow = mazeLine1[0]
mazeColumn = mazeLine1[1]
mazeInfo = []
for line in inputMazeFile:
line = line[ : -1]
tempList = line.split(" ")
mazeInfoC = [int(tempList[3][-1]), int(tempList[5][-1])]
mazeInfo.append(mazeInfoC)
inputMazeFile.close()
maze = []
counter = 0
counter2 = 0
for i in range(2 * int(mazeRow) + 1): #creates maze starting from row 0 and appends to the maze list, thus maze is genreated upside down
if i == (2 * int(mazeRow)): #but while printing maze it is reverted back so it prints it normal
mazeC = ["#"] * (3 * int(mazeColumn) + 1)
maze.append(mazeC)
elif i % 2 == 0: #this line only consists of up and down walls
mazeC = ["#"]
for k in range(int(mazeColumn)):
if mazeInfo[(counter2 * int(mazeColumn)) + k][1] == 1:
mazeC.append("###")
else:
if (mazeInfo[(counter2 * int(mazeColumn)) + k][0] == 1):
mazeC.append(" #")
elif ((((counter2 - 1) * int(mazeColumn)) + k) >= 0) and (mazeInfo[((counter2 - 1) * int(mazeColumn)) + k][0] == 1):
mazeC.append(" #")
else:
mazeC.append(" ")
counter2 += 1
maze.append(mazeC)
elif i % 2 == 1: # this line is where left and right walls are printed
mazeC = ["#"]
for k in range(int(mazeColumn)):
if mazeInfo[(counter * int(mazeColumn)) + k][0] == 1:
mazeC.append(" #")
else:
mazeC.append(" ")
counter += 1
maze.append(mazeC)
solutionInfo = []
for line in inputSolutionFile:
line = line.split(" ")
solC = [int(line[0]), int(line[1])]
solutionInfo.append(solC)
inputSolutionFile.close()
value = maze[2 * solutionInfo[0][1] + 1][solutionInfo[0][0] + 1]
if solutionInfo[1][1] - solutionInfo[0][1] == 1: #solution starts by going up
if value == " #":
value = "OO#"
value2 = "▲▲#"
else:
value2 = maze[2 * solutionInfo[0][1] + 2][solutionInfo[0][0] + 1]
if value2 == " #":
value = "OO "
value2 = "▲▲#"
else:
value = "OOO"
value2 = "▲▲▲"
maze[2 * solutionInfo[0][1] + 2][solutionInfo[0][0] + 1] = value2
elif solutionInfo[1][1] - solutionInfo[0][1] == -1:#solution starts by going down
if value == " #":
value = "OO#"
value2 = "▼▼#"
else:
value2 = maze[2 * solutionInfo[0][1]][solutionInfo[0][0] + 1]
if value2 == " #":
value = "OO "
value2 = "▼▼#"
else:
value = "OOO"
value2 = "▼▼▼"
maze[2 * solutionInfo[0][1]][solutionInfo[0][0] + 1] = value2
elif solutionInfo[1][0] - solutionInfo[0][0] == 1:#solution starts by going right
value = "OOO"
elif solutionInfo[1][0] - solutionInfo[0][0] == -1:#solution starts by going left
if value == " #":
value = "OO#"
else:
value = "OOO"
maze[2 * solutionInfo[0][1] + 1][solutionInfo[0][0] + 1] = value
for i in range(1, len(solutionInfo) - 1):
if solutionInfo[i + 1][0] - solutionInfo[i][0] == 1:
maze[2 * solutionInfo[i][1] + 1][solutionInfo[i][0] + 1] = "►►►"
elif solutionInfo[i + 1][0] - solutionInfo[i][0] == -1:
value = maze[2 * solutionInfo[i][1] + 1][solutionInfo[i][0] + 1]
if value == " #":
value = "◄◄#"
else:
value = "◄◄◄"
maze[2 * solutionInfo[i][1] + 1][solutionInfo[i][0] + 1] = value
elif solutionInfo[i + 1][1] - solutionInfo[i][1] == 1:
value = maze[2 * solutionInfo[i][1] + 1][solutionInfo[i][0] + 1]
if value == " #":
value = "▲▲#"
value2 = maze[2 * solutionInfo[i][1] + 2][solutionInfo[i][0] + 1]
value2 = "▲▲#"
else:
value2 = maze[2 * solutionInfo[i][1] + 2][solutionInfo[i][0] + 1]
if value2 == " #":
value2 = "▲▲#"
if solutionInfo[i][0] - solutionInfo[i - 1][0] == 1:
value = "▲▲ "
elif solutionInfo[i][0] - solutionInfo[i - 1][0] == -1:
value = "▲▲◄"
else:
value = "▲▲▲"
value2 = "▲▲▲"
maze[2 * solutionInfo[i][1] + 1][solutionInfo[i][0] + 1] = value
maze[2 * solutionInfo[i][1] + 2][solutionInfo[i][0] + 1] = value2
elif solutionInfo[i + 1][1] - solutionInfo[i][1] == -1:
value = maze[2 * solutionInfo[i][1] + 1][solutionInfo[i][0] + 1]
if value == " #":
value = "▼▼#"
value2 = "▼▼#"
else:
value2 = maze[2 * solutionInfo[i][1]][solutionInfo[i][0] + 1]
if value2 == " #":
value2 = "▼▼#"
if solutionInfo[i][0] - solutionInfo[i - 1][0] == 1:
value = "▼▼ "
elif solutionInfo[i][0] - solutionInfo[i - 1][0] == -1:
value = "▼▼◄"
elif value == " ":
value = "▼▼ "
elif value == " #":
value = "▼▼#"
else:
value = "▼▼▼"
value2 = "▼▼▼"
maze[2 * solutionInfo[i][1] + 1][solutionInfo[i][0] + 1] = value
maze[2 * solutionInfo[i][1]][solutionInfo[i][0] + 1] = value2
value = maze[2 * solutionInfo[len(solutionInfo) - 1][1] + 1][solutionInfo[len(solutionInfo) - 1][0] + 1]
if value == " ":
value = "XXX"
else:
value = "XX" + value[-1]
maze[2 * solutionInfo[len(solutionInfo) - 1][1] + 1][solutionInfo[len(solutionInfo) - 1][0] + 1] = value
printMaze(maze)