-
Notifications
You must be signed in to change notification settings - Fork 10
/
test.py
113 lines (91 loc) · 3.23 KB
/
test.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
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
import sys
if "python-sc2" not in sys.path:
sys.path.insert(1, "python-sc2")
import sc2pathlib
import time
from typing import List
def read_maze(file_name: str) -> List[List[int]]:
with open(file_name, "r") as text:
m = text.read()
lines = m.split("\n")
final_maze = []
height = len(lines[0])
width = len(lines)
for y in range(0, height):
maze_line = []
final_maze.append(maze_line)
for x in range(0, width):
maze_line.append(int(lines[x][height - 1 - y]))
return final_maze
maze = read_maze("tests/maze4x4.txt")
pf = sc2pathlib.PathFinder(maze)
print(pf.map)
print(pf.width)
print(pf.height)
print(pf.find_path((0, 0), (0, 2)))
pf.normalize_influence(100)
print(pf.lowest_influence_in_grid((2, 2), 5))
print(pf.find_path((0, 0), (0, 2)))
maze = read_maze("tests/AutomatonLE.txt")
pf = sc2pathlib.PathFinder(maze)
pf.normalize_influence(10)
pf.heuristic_accuracy = 0
result = pf.find_path((32, 51), (150, 129))
print(f"path distance 0: {result[1]} for path: {result[0]}")
pf.heuristic_accuracy = 1
result = pf.find_path((32, 51), (150, 129))
print(f"path distance 1: {result[1]} for path: {result[0]}")
pf.heuristic_accuracy = 2
result = pf.find_path((32, 51), (150, 129))
print(f"path distance 2: {result[1]} for path: {result[0]}")
pf.heuristic_accuracy = 0
result = pf.find_path((32, 51), (150, 129), influence=True)
print(f"path influenced distance 0: {result[1]} for path: {result[0]}")
pf.heuristic_accuracy = 1
result = pf.find_path((32, 51), (150, 129), influence=True)
print(f"path influenced distance 1: {result[1]} for path: {result[0]}")
pf.heuristic_accuracy = 2
result = pf.find_path((32, 51), (150, 129), influence=True)
print(f"path influenced distance 2: {result[1]} for path: {result[0]}")
expansions = [
(29, 65), (35, 34),
(63, 26), (56, 65),
(98, 26), (80, 66),
(33, 105), (129, 28),
(54, 151), (150, 74),
(103, 113), (85, 153),
(127, 114), (120, 153),
(148, 145), (154, 114)
]
total_distance = 0
count = 0
ns_pf = time.perf_counter_ns()
pf.normalize_influence(100)
pf.heuristic_accuracy = 1
for pos1 in expansions:
for pos2 in expansions:
result = pf.find_path(pos1, pos2, False)
total_distance += result[1]
count += 1
ns_pf = time.perf_counter_ns() - ns_pf
print(f"pathfinding took {ns_pf / 1000 / 1000} ms. Total distance {total_distance}")
print(f"pathfinding took {ns_pf / 1000 / 1000 / count} ms per path.")
ns_pf = time.perf_counter_ns()
pf.add_influence([(56, 65), (110, 28), (100, 98)], 150, 10, False)
ns_pf = time.perf_counter_ns() - ns_pf
print(f"adding influence took {ns_pf / 1000 / 1000} ms.")
pf.normalize_influence(100)
ns_pf = time.perf_counter_ns()
pf.add_influence_walk([(56, 65), (110, 28), (100, 98)], 150, 10, False)
ns_pf = time.perf_counter_ns() - ns_pf
print(f"adding influence by walking distance took {ns_pf / 1000 / 1000} ms.")
result = pf.find_path((29, 65), (154, 114))
print("Distance between bases: " + str(result[1]))
result = pf.find_path_influence((29, 65), (154, 114))
# print(pf.map)
# pf.reset()
# pf.normalize_influence(100)
pf.plot(result[0])
pf.create_block([(11.5, 11.5), (21.5, 21.5), (31.5, 31.5), (31.5, 31.5)], (2, 1))
pf.plot(result[0])
input("Press Enter to continue...")