forked from DrInfy/sc2-pathlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_map.py
88 lines (71 loc) · 2.21 KB
/
test_map.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
import sc2pathlibp
import time
from typing import List
import numpy as np
import time
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 = []
for y in range(0, len(lines[0])):
maze_line = []
final_maze.append(maze_line)
for x in range(0, len(lines)):
maze_line.append(int(lines[x][y]))
return final_maze
class Rect:
def __init__(self, x: int, y: int, width: int, height: int):
self.x = x
self.y = y
self.width = width
self.height = height
# playable_area = Rect(2, 2, 38, 38)
# maze = read_maze("tests/choke.txt")
# map = sc2pathlibp.Sc2Map(maze, maze, maze, playable_area)
# print(f"Choke lines found: {len(map.chokes)}")
# map.plot("cliffs")
# map.plot_chokes("chokes")
# input("Press Enter to continue...")
map_name = "AutomatonLE"
pathing = np.load(f"tests/{map_name}_pathing.npy")
placement = np.load(f"tests/{map_name}_placement.npy")
height = np.load(f"tests/{map_name}_height.npy")
playable_area = Rect(18, 16, 148, 148) # AutomatonLE
ns_pf = time.perf_counter_ns()
map = sc2pathlibp.Sc2Map(pathing, placement, height, playable_area)
ns_pf = time.perf_counter_ns() - ns_pf
print(f"Creating map object took {ns_pf / 1000 / 1000} ms.")
print(map.overlord_spots)
map.plot("cliffs")
map.plot_chokes("chokes")
print(f"Choke lines found: {len(map.chokes)}")
arr = []
for choke in map.chokes:
arr.append(choke.main_line)
# Available properties
# choke.lines
# choke.side1
# choke.side2
# choke.pixels
# choke.min_length
print(arr)
ns_pf = time.perf_counter_ns()
map._map.calculate_zones([
(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)
])
ns_pf = time.perf_counter_ns() - ns_pf
print(f"Solving map zones took {ns_pf / 1000 / 1000} ms.")
ns_pf = time.perf_counter_ns()
map.add_influence_without_zones([1, 2], 1000)
ns_pf = time.perf_counter_ns() - ns_pf
print(f"Adding map influence took {ns_pf / 1000 / 1000} ms.")
map.plot_zones("zones")
input("Press Enter to continue...")