Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sc2
- import random
- from sc2 import Race, Difficulty
- from sc2.position import Point2, Point3
- from sc2.unit import Unit
- from sc2.player import Bot, Computer
- from sc2.player import Human
- from sc2.ids.unit_typeid import UnitTypeId
- from sc2.ids.ability_id import AbilityId
- from sc2.units import Units
- class MicroBot(sc2.BotAI):
- async def buildExpansion(self, iteration):
- if (self.can_afford(UnitTypeId.COMMANDCENTER)):
- workers = self.workers.gathering
- if (workers):
- worker = workers.furthest_to(workers.center);
- # If a placement location was found
- location = await self.get_next_expansion()
- if location:
- # Order worker to build exactly on that location
- self.do(worker.build(UnitTypeId.COMMANDCENTER, location), subtract_cost=True);
- async def buildCommandCenter(self, iteration):
- if (self.can_afford(UnitTypeId.COMMANDCENTER)):
- workers = self.workers.gathering
- if (workers):
- worker = workers.furthest_to(workers.center);
- # If a placement location was found
- location = await self.find_placement(UnitTypeId.COMMANDCENTER, worker.position, placement_step=3)
- if location:
- # Order worker to build exactly on that location
- self.do(worker.build(UnitTypeId.COMMANDCENTER, location), subtract_cost=True);
- async def buildSCVs(self, iteration):
- if (
- self.can_afford(UnitTypeId.SCV)
- and self.supply_left > 0
- and (
- self.structures(UnitTypeId.BARRACKS).ready.amount < 1
- and self.townhalls(UnitTypeId.COMMANDCENTER).idle
- or self.townhalls(UnitTypeId.ORBITALCOMMAND).idle
- )
- ):
- for th in self.townhalls.idle:
- self.do(th.train(UnitTypeId.SCV), subtract_cost=True, subtract_supply=True)
- async def manageIdleWorkers(self, iteration):
- if self.townhalls:
- for w in self.workers.idle:
- th = self.townhalls.closest_to(w)
- mfs = self.mineral_field.closer_than(10, th)
- if mfs:
- mf = mfs.closest_to(w)
- self.do(w.gather(mf))
- async def attackOpponent(self, iteration):
- for worker in self.workers:
- self.do(worker.attack(self.enemy_start_locations[0]))
- async def on_step(self, iteration: int):
- if iteration >= 0:
- if (self.supply_left <= 10):
- await self.buildExpansion(iteration)
- if (self.supply_workers >= 70):
- await self.attackOpponent(iteration)
- await self.buildSCVs(iteration)
- await self.manageIdleWorkers(iteration)
- sc2.run_game(sc2.maps.get("AcropolisLE"), [
- Bot(Race.Terran, MicroBot()),
- Computer(Race.Protoss, Difficulty.Medium)
- ], realtime=False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement