Skip to content

Commit

Permalink
Merge pull request #81 from FredNoonienSingh/75-premove-workers
Browse files Browse the repository at this point in the history
workers now premove to the build pos
  • Loading branch information
FredNoonienSingh authored Jan 11, 2025
2 parents 71817a1 + 94dcb49 commit 2f237d9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
11 changes: 10 additions & 1 deletion bot/HarstemsAunt/macro.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from sc2.unit import Unit
from sc2.units import Units
from sc2.bot_ai import BotAI
from sc2.game_data import Cost
from sc2.ids.buff_id import BuffId
from sc2.position import Point2, Point3
from sc2.ids.ability_id import AbilityId
Expand Down Expand Up @@ -62,7 +63,7 @@ async def __call__(self):

def get_build_worker(self) -> Unit:
""" returns the build worker """
return self.bot.workers.closest_to(self.build_order.get_build_pos())
return self.bot.workers.closest_n_units(self.build_order.get_build_pos(), 1)[0]

def get_production_structure(self, unit_type: UnitTypeId) -> UnitTypeId:
""" returns the appropriate production structure
Expand Down Expand Up @@ -146,12 +147,20 @@ async def train_unit(next_step:BuildInstruction):
#TODO: #77 STOP COUNTER FROM GOING CRAZY
self.build_order.increment_step()


next_step: BuildInstruction = self.build_order.next_instruction()
if not next_step and self.build_order.buffer:
next_step = self.build_order.get_instruction_from_buffer()
if not next_step and not self.build_order.buffer:
return

if not next_step.type_id == UnitTypeId.ASSIMILATOR:
structure_cost:Cost = self.bot.calculate_cost(next_step.type_id)
if (self.bot.minerals > (structure_cost.minerals*0.65)):
if not Utils.unittype_in_proximity_to_point(self.bot, UnitTypeId.PROBE, next_step.position):
worker: Unit = self.get_build_worker()
worker.move(next_step.position)

match next_step.instruction_type:
case InstructionType.BUILD_STRUCTURE:
await construct_building(next_step)
Expand Down
7 changes: 6 additions & 1 deletion bot/HarstemsAunt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from sc2.unit import Unit
from sc2.bot_ai import BotAI
from sc2.game_data import GameData
from sc2.position import Point2, Point3
from sc2.ids.upgrade_id import UpgradeId
from sc2.ids.unit_typeid import UnitTypeId
Expand Down Expand Up @@ -133,9 +134,13 @@ def get_warp_in_pos(bot:BotAI) -> Union[Point2, Point3, Unit]:
if bot.enemy_units:
active_prism = bot.units(UnitTypeId.WARPPRISM).closest_to(bot.enemy_units.center)
else:
active_prism = bot.units(UnitTypeId.WARPPRISM).closest_to(bot.enemy_start_locations[0])
active_prism = bot.units(UnitTypeId.WARPPRISM).closest_to(bot.enemy_start_locations[0])
return active_prism.position

@staticmethod
def unittype_in_proximity_to_point(bot:BotAI,type_id:UnitTypeId,point:Union[Point2,Point3,Unit],max_distance:float=.5) -> bool:
return bot.units(type_id).filter(lambda unit: unit.distance_to(point)<max_distance)

@staticmethod
def structure_in_proximity(bot:BotAI, structure_type:UnitTypeId, structure:Unit, max_distance:float)-> bool:
if bot.structures(structure_type).filter(lambda struct: struct.distance_to(structure)<max_distance):
Expand Down

0 comments on commit 2f237d9

Please sign in to comment.