forked from harrischristiansen/generals-bot
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathGatherAnalyzer.py
More file actions
45 lines (34 loc) · 1.38 KB
/
GatherAnalyzer.py
File metadata and controls
45 lines (34 loc) · 1.38 KB
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
import SearchUtils
from Interfaces import MapMatrixInterface
from base.client.map import MapBase, Tile
from MapMatrix import MapMatrix
class GatherAnalyzer(object):
def __init__(self, map: MapBase):
self.gather_locality_map: MapMatrixInterface[int] = MapMatrix(map, 0)
self.map = map
def __getstate__(self):
state = self.__dict__.copy()
if "map" in state:
del state["map"]
return state
def __setstate__(self, state):
self.__dict__.update(state)
self.map = None
def scan(self):
"""
Look for pockets of far away army and put weights on them
@return:
"""
self.gather_locality_map: MapMatrixInterface[int] = MapMatrix(self.map, 0)
for tile in self.map.pathable_tiles:
if tile.player != self.map.player_index:
continue
def counter(nearbyTile: Tile):
if nearbyTile.isObstacle:
return True
if nearbyTile.isCity or nearbyTile.isGeneral:
# Skip cities because we want to gather TILES not CITIES :|
return
if nearbyTile.player == self.map.player_index:
self.gather_locality_map[tile] += nearbyTile.army - 1
SearchUtils.breadth_first_foreach(self.map, [tile], maxDepth=4, foreachFunc=counter, noLog=True)