@@ -78,31 +78,29 @@ async def on_step(self, iteration: int):
7878 # Near same command as above with the depot
7979 await self .build (UnitTypeId .BARRACKS , near = cc .position .towards (self .game_info .map_center , 8 ))
8080
81- # If we have a barracks (complete or under construction) and less than 2 gas structures (here: refineries)
82- elif self .structures (UnitTypeId .BARRACKS ) and self .gas_buildings .amount < 2 :
83- if self .can_afford (UnitTypeId .REFINERY ):
84- # All the vespene geysirs nearby, including ones with a refinery on top of it
85- vgs = self .vespene_geyser .closer_than (10 , cc )
86- for vg in vgs :
87- if self .gas_buildings .filter (lambda unit : unit .distance_to (vg ) < 1 ):
88- continue
89- # Select a worker closest to the vespene geysir
90- worker : Unit | None = self . select_build_worker ( vg )
91- # Worker can be none in cases where all workers are dead
92- # or 'select_build_worker' function only selects from workers which carry no minerals
93- if worker is None :
94- continue
81+ # If we have a barracks (complete or under construction) and less than 2 gas structures (here: refineries)
82+ if self .structures (UnitTypeId .BARRACKS ) and self .gas_buildings .amount < 2 :
83+ if self .can_afford (UnitTypeId .REFINERY ):
84+ # All the vespene geysirs nearby, including ones with a refinery on top of it
85+ vgs = self .vespene_geyser .closer_than (10 , cc )
86+ for vg in vgs :
87+ has_refinery = self .gas_buildings .filter (lambda unit : unit .distance_to (vg ) < 1 )
88+ if has_refinery :
89+ continue
90+ # Select a worker closest to the vespene geysir
91+ worker : Unit | None = self . select_build_worker ( vg )
92+ # Worker can be none in cases where all workers are dead
93+ # or 'select_build_worker' function only selects from workers which carry no minerals
94+ if worker is not None :
9595 # Issue the build command to the worker, important: vg has to be a Unit, not a position
9696 worker .build_gas (vg )
97- # Only issue one build geysir command per frame
98- break
99-
100- # If we have at least one barracks that is compelted, build factory
101- if self .structures (UnitTypeId .BARRACKS ).ready :
102- if self .structures (UnitTypeId .FACTORY ).amount < 3 and not self .already_pending (UnitTypeId .FACTORY ):
103- if self .can_afford (UnitTypeId .FACTORY ):
104- position : Point2 = cc .position .towards_with_random_angle (self .game_info .map_center , 16 )
105- await self .build (UnitTypeId .FACTORY , near = position )
97+
98+ # If we have at least one barracks that is completed, build factory
99+ if self .structures (UnitTypeId .BARRACKS ).ready :
100+ if self .structures (UnitTypeId .FACTORY ).amount < 3 and not self .already_pending (UnitTypeId .FACTORY ):
101+ if self .can_afford (UnitTypeId .FACTORY ):
102+ position : Point2 = cc .position .towards_with_random_angle (self .game_info .map_center , 16 )
103+ await self .build (UnitTypeId .FACTORY , near = position )
106104
107105 for factory in self .structures (UnitTypeId .FACTORY ).ready .idle :
108106 # Reactor allows us to build two at a time
0 commit comments