-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
66 lines (57 loc) · 1.63 KB
/
main.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
from maps import *
from utils import *
from Graph import *
from visualise import AppWindow, Recorder
from Map import Map
from video import save_video
def main():
recorder = Recorder()
map_ = Map(map1)
fname = "map1"
rows, cols = map_.getSize()
if rows % 2 == 0:
pass
initial_position = map_.getStartPosition()
k = 0
nodes = []
for i in range(0, rows, 2):
r = (i, i + 1) if (i+1) < rows else [i]
for j in range(0, cols, 2):
c = (j, j + 1) if (j+1) < cols else [j]
w = [(ri,ci) for ri in r for ci in c]
if not map_.isOccupied(r, c):
if initial_position in w:
startIndex = w.index(initial_position)
else:
startIndex = None
# creating nodes
n = Node(k, w, startIndex)
nodes.append(n)
k += 1
# creating pairs of nodes
edges = find_pairs(nodes)
# generating graph for nearby nodes
edges = form_graph(edges)
G = Graph(edges)
G.draw(fname)
T = Tree(G.MST, map_)
T.printTree()
path, route = T.traversing()
# (row, col) path of the grid map taken by the robot
print(path)
app = AppWindow(map_, initial_position)
i = 0
while app.runningStatus() and i < len(path):
r, c = path[i]
map_.markVisited(r, c)
app.updateRobot(r,c)
app.updateMap(map_)
app.drawGrid()
app.drawRobot()
app.update()
recorder.save(app.screen)
i += 1
app.exit()
save_video(fname)
if __name__ == "__main__":
main()