|
| 1 | +import sc2 |
| 2 | +from sc2 import run_game, maps, Race, Difficulty |
| 3 | +from sc2.player import Bot, Computer |
| 4 | +from sc2.constants import NEXUS, PROBE, PYLON, ASSIMILATOR |
| 5 | +## producing more workers |
| 6 | +## We just need a nexus for producing workers |
| 7 | +## reference a nexus |
| 8 | +##### Tutorial II ##### |
| 9 | +# specify where - which map |
| 10 | +# player list |
| 11 | +# run-speed -T - nomral speed, F = ultra fast |
| 12 | +# each pylon - increase your supplies |
| 13 | +# each pylon builds the scionic tree |
| 14 | +# building pylons and simulators |
| 15 | +# each pylon adds to the scionic matrix |
| 16 | +# scionic matrix helps to build more buildings |
| 17 | +# need to optimise the pylon to not build one next to the |
| 18 | +# other |
| 19 | +# baseless to have more than 3 patch of workers for each |
| 20 | +# mineral or we will exhaust our resources of workers |
| 21 | +#### Tutorial III ##### Geysers and Expanding |
| 22 | +# When to expand ? to 2 or 3 nexus areas |
| 23 | + |
| 24 | + |
| 25 | +class SentdeBot(sc2.BotAI): |
| 26 | + async def on_step(self, iteration): |
| 27 | + # define an ansynchronous method |
| 28 | + # every step we get, what will we do |
| 29 | + await self.distribute_workers() |
| 30 | + #already defined |
| 31 | + await self.builder_workers() |
| 32 | + #doesnt exist yet |
| 33 | + await self.build_pylons() |
| 34 | + await self.build_assimilators() |
| 35 | + await self.expand() |
| 36 | + |
| 37 | + |
| 38 | + async def builder_workers(self): |
| 39 | + for nexus in self.units(NEXUS).ready.noqueue: |
| 40 | + # Nexus must be ready |
| 41 | + # no queue - nothing else in the queue |
| 42 | + if self.can_afford(PROBE): |
| 43 | + ## inherited probe |
| 44 | + await self.do(nexus.train(PROBE)) |
| 45 | + |
| 46 | + async def build_pylons(self): |
| 47 | + ## create some logic for resource management |
| 48 | + if self.supply_left < 5 and not self.already_pending(PYLON): |
| 49 | + nexuses = self.units(NEXUS).ready |
| 50 | + if nexuses.exists: |
| 51 | + if self.can_afford(PYLON): |
| 52 | + # specify build and where - location |
| 53 | + await self.build(PYLON, near=nexuses.first) |
| 54 | + |
| 55 | + async def build_assimilators(self): |
| 56 | + for nexus in self.units(NEXUS).ready: |
| 57 | + ## find the vespian geysers |
| 58 | + vaspenes = self.state.vespene_geyser.closer_thann(25.0, nexus) |
| 59 | + for vaspene in vaspenes: |
| 60 | + if not self.can_afford(ASSIMILATOR): |
| 61 | + break |
| 62 | + worker = self.select_build_worker(vaspene.position) |
| 63 | + if worker is None: |
| 64 | + break |
| 65 | + if not self.units(ASSIMILATOR).closer_than(1.0, vaspene).exists: |
| 66 | + await self.do(worker.build(ASSIMILATOR, vaspene)) |
| 67 | + |
| 68 | + async def expand(self): |
| 69 | + if self.units(NEXUS).amount < 3 and self.can_afford(NEXUS): |
| 70 | + await self.expand_now() |
| 71 | + ## best situation will be to detect a soldier's rush or knight's rush |
| 72 | + ## by the enemy and then decide how many nexuses to expand |
| 73 | + |
| 74 | +run_game(maps.get("AbyssalReefLE"), [Bot(Race.Protoss, SentdeBot()), Computer(Race.Terran, Difficulty.Easy)], realtime=False) |
0 commit comments