forked from Dentosal/python-sc2
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathzerg_rush.py
More file actions
110 lines (91 loc) · 4.32 KB
/
zerg_rush.py
File metadata and controls
110 lines (91 loc) · 4.32 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
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
import random
import sc2
from sc2 import Race, Difficulty
from sc2.constants import *
from sc2.player import Bot, Computer
class ZergRushBot(sc2.BotAI):
def __init__(self):
self.drone_counter = 0
self.extractor_started = False
self.spawning_pool_started = False
self.moved_workers_to_gas = False
self.moved_workers_from_gas = False
self.queeen_started = False
self.mboost_started = False
async def on_step(self, iteration):
if iteration == 0:
await self.chat_send("(glhf)")
if not self.units(HATCHERY).ready.exists:
for unit in self.workers | self.units(ZERGLING) | self.units(QUEEN):
await self.do(unit.attack(self.enemy_start_locations[0]))
return
hatchery = self.units(HATCHERY).ready.first
larvae = self.units(LARVA)
target = self.known_enemy_structures.random_or(self.enemy_start_locations[0]).position
for zl in self.units(ZERGLING).idle:
await self.do(zl.attack(target))
for queen in self.units(QUEEN).idle:
abilities = await self.get_available_abilities(queen)
if AbilityId.EFFECT_INJECTLARVA in abilities:
await self.do(queen(EFFECT_INJECTLARVA, hatchery))
if self.vespene >= 100:
sp = self.units(SPAWNINGPOOL).ready
if sp.exists and self.minerals >= 100 and not self.mboost_started:
await self.do(sp.first(RESEARCH_ZERGLINGMETABOLICBOOST))
self.mboost_started = True
if not self.moved_workers_from_gas:
self.moved_workers_from_gas = True
for drone in self.workers:
m = self.state.mineral_field.closer_than(10, drone.position)
await self.do(drone.gather(m.random, queue=True))
if self.supply_left < 2:
if self.can_afford(OVERLORD) and larvae.exists:
await self.do(larvae.random.train(OVERLORD))
if self.units(SPAWNINGPOOL).ready.exists:
if larvae.exists and self.can_afford(ZERGLING):
await self.do(larvae.random.train(ZERGLING))
if self.units(EXTRACTOR).ready.exists and not self.moved_workers_to_gas:
self.moved_workers_to_gas = True
extractor = self.units(EXTRACTOR).first
for drone in self.workers.random_group_of(3):
await self.do(drone.gather(extractor))
if self.minerals > 500:
for d in range(4, 15):
pos = hatchery.position.to2.towards(self.game_info.map_center, d)
if await self.can_place(HATCHERY, pos):
self.spawning_pool_started = True
await self.do(self.workers.random.build(HATCHERY, pos))
break
if self.drone_counter < 3:
if self.can_afford(DRONE):
self.drone_counter += 1
await self.do(larvae.random.train(DRONE))
if not self.extractor_started:
if self.can_afford(EXTRACTOR):
drone = self.workers.random
target = self.state.vespene_geyser.closest_to(drone.position)
err = await self.do(drone.build(EXTRACTOR, target))
if not err:
self.extractor_started = True
elif not self.spawning_pool_started:
if self.can_afford(SPAWNINGPOOL):
for d in range(4, 15):
pos = hatchery.position.to2.towards(self.game_info.map_center, d)
if await self.can_place(SPAWNINGPOOL, pos):
drone = self.workers.closest_to(pos)
err = await self.do(drone.build(SPAWNINGPOOL, pos))
if not err:
self.spawning_pool_started = True
break
elif not self.queeen_started and self.units(SPAWNINGPOOL).ready.exists:
if self.can_afford(QUEEN):
r = await self.do(hatchery.train(QUEEN))
if not r:
self.queeen_started = True
def main():
sc2.run_game(sc2.maps.get("Abyssal Reef LE"), [
Bot(Race.Zerg, ZergRushBot()),
Computer(Race.Terran, Difficulty.Medium)
], realtime=False, save_replay_as="ZvT.SC2Replay")
if __name__ == '__main__':
main()