-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
53 lines (41 loc) · 1.26 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@Time : 20/8/19 16:44
@Author : Jedidiah
@Contact : [email protected]
@File : main.py
@Software: PyCharm
"""
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
from PathFinder import RandomMap, PathFinder
plt.figure(figsize=(6, 6))
graph = RandomMap.RandomMap(size=50)
ax = plt.gca()
ax.set_xlim([0, graph.size])
ax.set_ylim([0, graph.size])
for i in range(graph.size):
for j in range(graph.size):
if graph.IsObstacle(PathFinder.Point(i, j)):
rec = Rectangle((i, j), width=1, height=1, color='gray')
ax.add_patch(rec)
else:
rec = Rectangle((i, j), width=1, height=1, edgecolor='gray', facecolor='w')
ax.add_patch(rec)
rec = Rectangle((0, 0), width=1, height=1, facecolor='b')
ax.add_patch(rec)
rec = Rectangle((graph.size - 1, graph.size - 1), width=1, height=1, facecolor='r')
ax.add_patch(rec)
plt.axis('equal')
plt.axis('off')
plt.tight_layout()
# plt.show()
# print("Dijkstra: ")
# Dijkstra = PathFinder.FindPath(graph, heuristic=False)
# Dijkstra.Run(ax, plt)
print("A star: ")
aStar = PathFinder.FindPath(graph)
aStar.Run(ax, plt)
print("====================================================================")
plt.show()