Creating SC2 Bots with Python
Making StarCraft II bots with python
Python으로 Alphastar를 만들어 보자!!
다음은 Cannon Rush Bot을 만드는 과정이다.
import random
import sc2
from sc2 import Race, Difficulty
from sc2.constants import *
from sc2.player import Bot, Computer
class CannonRushBot(sc2.BotAI):
async def on_step(self, iteration):
if iteration == 0:
await self.chat_send("(probe)(pylon)(cannon)(cannon)(gg)")
if not self.units(NEXUS).exists:
for worker in self.workers:
await self.do(worker.attack(self.enemy_start_locations[0]))
return
else:
nexus = self.units(NEXUS).first
if self.workers.amount < 16 and nexus.is_idle:
if self.can_afford(PROBE):
await self.do(nexus.train(PROBE))
...
Proxy Rax Rush
class ProxyRaxBot(sc2.BotAI):
def __init__(self):
self.attack_groups = set()
async def on_step(self, iteration):
...
elif self.supply_left < (2 if self.units(BARRACKS).amount < 3 else 4):
if self.can_afford(SUPPLYDEPOT) and self.already_pending(SUPPLYDEPOT) < 2:
await self.build(SUPPLYDEPOT, near=cc.position.towards(self.game_info.map_center, 5))
elif self.units(BARRACKS).amount < 3 or (self.minerals > 400 and self.units(BARRACKS).amount < 5):
if self.can_afford(BARRACKS):
p = self.game_info.map_center.towards(self.enemy_start_locations[0], 25)
await self.build(BARRACKS, near=p)
for rax in self.units(BARRACKS).ready.idle:
if not self.can_afford(MARINE):
break
await self.do(rax.train(MARINE))
...