-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheg.py
84 lines (67 loc) · 2.32 KB
/
eg.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
import sc2
from sc2 import run_game, maps, Race, Difficulty
from sc2.ids.unit_typeid import UnitTypeId
from sc2.player import Bot, Computer
from sc2.position import Point2
from sc2.unit import Unit
import logging
from genmgr import GeneralManager
from MapAnalyzer import MapData
from queens_sc2.queens import Queens
from queen_policy import QueenPolicy
from random import shuffle
from typing import Union
from numpy import ndarray
from logger import Sc2Logger
logging.basicConfig(
level=logging.DEBUG,
filename="egbot.log",
datefmt="%d-%m-%y %H:%M:%S",
format="%(asctime)s | %(levelname)s | %(funcName)s | ln:%(lineno)d | %(message)s",
)
class EGbot(sc2.BotAI):
def __init__(self):
super().__init__()
self.qp = None
self.gm = GeneralManager(self)
self.iteration = 0
self.logger = Sc2Logger()
async def on_start(self):
self.gm.setup()
async def on_step(self, iteration):
self.iteration = iteration
# if iteration == 0:
# await self.chat_send("(glhf)")
await self.gm.manage(iteration)
if iteration % 120 == 0:
await self.log_info()
async def on_before_start(self):
mfs = self.mineral_field.closer_than(10, self.townhalls.random)
for drone in self.units(UnitTypeId.DRONE):
drone.gather(mfs.closest_to(drone))
async def on_building_construction_complete(self, unit: Unit):
if unit.type_id == UnitTypeId.HATCHERY:
if self.mineral_field:
mf = self.mineral_field.closest_to(unit)
unit.smart(mf)
async def on_unit_created(self, unit: Unit):
pass
async def on_unit_destroyed(self, unit_tag: int):
self.gm.queens.remove_unit(unit_tag)
pass
async def on_unit_type_changed(self, unit: Unit, previous_type: UnitTypeId):
pass
async def log_info(self):
res = await self.logger.log_worker_distribution(self)
logging.info(res)
async def control_enemy(self):
await self.client.debug_control_enemy()
def main():
"""Setting realtime=False makes the game/bot play as fast as possible"""
run_game(
maps.get("AbyssalReefLE"),
[Bot(Race.Zerg, EGbot()), Computer(Race.Terran, Difficulty.Easy)],
realtime=False,
)
if __name__ == "__main__":
main()