Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. import sc2
  2. import random
  3.  
  4. from sc2 import Race, Difficulty
  5. from sc2.position import Point2, Point3
  6. from sc2.unit import Unit
  7. from sc2.player import Bot, Computer
  8. from sc2.player import Human
  9. from sc2.ids.unit_typeid import UnitTypeId
  10. from sc2.ids.ability_id import AbilityId
  11. from sc2.units import Units
  12.  
  13. class MicroBot(sc2.BotAI):
  14.  
  15. async def buildExpansion(self, iteration):
  16. if (self.can_afford(UnitTypeId.COMMANDCENTER)):
  17. workers = self.workers.gathering
  18. if (workers):
  19. worker = workers.furthest_to(workers.center);
  20. # If a placement location was found
  21. location = await self.get_next_expansion()
  22. if location:
  23. # Order worker to build exactly on that location
  24. self.do(worker.build(UnitTypeId.COMMANDCENTER, location), subtract_cost=True);
  25.  
  26.  
  27. async def buildCommandCenter(self, iteration):
  28. if (self.can_afford(UnitTypeId.COMMANDCENTER)):
  29. workers = self.workers.gathering
  30. if (workers):
  31. worker = workers.furthest_to(workers.center);
  32. # If a placement location was found
  33. location = await self.find_placement(UnitTypeId.COMMANDCENTER, worker.position, placement_step=3)
  34. if location:
  35. # Order worker to build exactly on that location
  36. self.do(worker.build(UnitTypeId.COMMANDCENTER, location), subtract_cost=True);
  37.  
  38. async def buildSCVs(self, iteration):
  39. if (
  40. self.can_afford(UnitTypeId.SCV)
  41. and self.supply_left > 0
  42. and (
  43. self.structures(UnitTypeId.BARRACKS).ready.amount < 1
  44. and self.townhalls(UnitTypeId.COMMANDCENTER).idle
  45. or self.townhalls(UnitTypeId.ORBITALCOMMAND).idle
  46. )
  47. ):
  48. for th in self.townhalls.idle:
  49. self.do(th.train(UnitTypeId.SCV), subtract_cost=True, subtract_supply=True)
  50.  
  51.  
  52. async def manageIdleWorkers(self, iteration):
  53. if self.townhalls:
  54. for w in self.workers.idle:
  55. th = self.townhalls.closest_to(w)
  56. mfs = self.mineral_field.closer_than(10, th)
  57. if mfs:
  58. mf = mfs.closest_to(w)
  59. self.do(w.gather(mf))
  60.  
  61. async def attackOpponent(self, iteration):
  62. for worker in self.workers:
  63. self.do(worker.attack(self.enemy_start_locations[0]))
  64.  
  65.  
  66.  
  67. async def on_step(self, iteration: int):
  68.  
  69. if iteration >= 0:
  70.  
  71. if (self.supply_left <= 10):
  72. await self.buildExpansion(iteration)
  73.  
  74. if (self.supply_workers >= 70):
  75. await self.attackOpponent(iteration)
  76.  
  77.  
  78. await self.buildSCVs(iteration)
  79. await self.manageIdleWorkers(iteration)
  80.  
  81.  
  82.  
  83.  
  84. sc2.run_game(sc2.maps.get("AcropolisLE"), [
  85. Bot(Race.Terran, MicroBot()),
  86. Computer(Race.Protoss, Difficulty.Medium)
  87. ], realtime=False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement