-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaze.py
78 lines (66 loc) · 2.43 KB
/
maze.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
import maze_generator
class Maze:
def __init__(self, size, goal):
self.field = maze_generator.MazeGenerator(size, goal).maze_generate()
self.size = size
def check_coordinate(self, coordinate):
if not (0 <= coordinate[0] < self.size[0] and 0 <= coordinate[1] < self.size[1]):
raise Exception("wrong coordinate")
def wall(self, coordinate):
self.check_coordinate(coordinate)
return self.field[coordinate][0:4]
def is_goal(self, coordinate):
self.check_coordinate(coordinate)
return self.field[coordinate][4]
def display_cui(self):
display_str = " "
for x in range(0, self.size[0]):
display_str += " " + str(x) + " "
display_str += " \n"
for y in range(self.size[1] - 1, -1, -1):
display_str += " "
for x in range(0, self.size[0]):
display_str += "8"
if self.field[(x, y, 2)] == 1:
display_str += "888"
else:
display_str += " "
display_str += "8 \n"
display_str += str(y) + " "
for x in range(0, self.size[0]):
if self.field[(x, y, 1)] == 1:
display_str += "8"
else:
display_str += " "
if self.field[(x, y, 4)] == 1:
display_str += " G "
else:
display_str += " "
if self.field[(self.size[0] - 1, y, 0)] == 1:
display_str += "8"
else:
display_str += " "
display_str += " " + str(y) + "\n"
display_str += " "
for x in range(0, self.size[0]):
display_str += "8"
if self.field[(x, 0, 3)] == 1:
display_str += "888"
else:
display_str += " "
display_str += "8\n"
display_str += " "
for x in range(0, self.size[0]):
display_str += " " + str(x) + " "
display_str += " \n"
print(display_str)
def dump_params(self):
csvstr = ""
for x in range(self.size[0]):
for y in range(self.size[1]):
csvstr += ",".join(str(int(i)) for i in self.field[(x, y)].tolist())
csvstr += ","
csvstr += "\n"
return csvstr
if __name__ == "__main__":
Maze((9, 9), (9, 5)).display_cui()