Exemple #1
0
 def __init__(self, base_location, minimap_target_x: int,
              minimap_target_y: int):
     Order.__init__(self)
     self.base_location = base_location
     self.actions = TerranActions()
     self.camera_moved = False
     self.minimap_target_x = minimap_target_x
     self.minimap_target_y = minimap_target_y
Exemple #2
0
 def __init__(self, base_location: Location, looping: bool = False):
     Order.__init__(self)
     self.base_location = base_location
     self.other_bases_minimap_locations = self.base_location.other_unknown_bases_locations_on_minimap(
     )
     self.actions = TerranActions()
     self.action_ids = TerranActionIds()
     self.unit_type_ids = UnitTypeIds()
     self.infinite_scouting = looping
Exemple #3
0
class Scouting(Order):

    actions: None
    action_ids: None
    unit_type_ids: None
    base_location = None
    other_bases_minimap_locations = None
    scv_selected = False
    scv_moved = False
    scv_back_to_base = False
    infinite_scouting = False

    def __init__(self, base_location: Location, looping: bool = False):
        Order.__init__(self)
        self.base_location = base_location
        self.other_bases_minimap_locations = self.base_location.other_unknown_bases_locations_on_minimap(
        )
        self.actions = TerranActions()
        self.action_ids = TerranActionIds()
        self.unit_type_ids = UnitTypeIds()
        self.infinite_scouting = looping

    def done(self, observations: Observations) -> bool:
        return self.scv_back_to_base and not self.infinite_scouting

    def execute(self, observations: Observations) -> actions.FunctionCall:
        if not self.scv_selected:
            unit_type = observations.screen().unit_type()
            unit_y, unit_x = (
                unit_type == self.unit_type_ids.terran_scv()).nonzero()
            rand_unit_index = random.randint(0, len(unit_y) - 1)
            target = [unit_x[rand_unit_index], unit_y[rand_unit_index]]
            self.scv_selected = True
            return self.actions.select_point(target)
        elif not self.scv_moved and self.action_ids.move_minimap(
        ) in observations.available_actions():
            unit_y, unit_x = self.other_bases_minimap_locations.pop(0)
            target = [unit_x, unit_y]
            self.scv_moved = True
            return self.actions.move_minimap(target)
        elif self.scv_moved and observations.player().idle_worker_count(
        ) > 0 and len(self.other_bases_minimap_locations) > 0:
            self.scv_moved = False
            return self.actions.select_idle_worker()
        elif self.infinite_scouting and len(
                self.other_bases_minimap_locations) == 0:
            self.other_bases_minimap_locations = self.base_location.other_unknown_bases_locations_on_minimap(
            )
        elif not self.scv_back_to_base and len(
                self.other_bases_minimap_locations) == 0:
            unit_y, unit_x = self.base_location.base_location_on_minimap()
            target = [unit_x, unit_y]
            self.scv_back_to_base = True
            return self.actions.move_minimap(target)
        return self.actions.no_op()
Exemple #4
0
class CenterCameraOnCommandCenter(Order):
    def __init__(self, base_location):
        Order.__init__(self)
        self.base_location = base_location
        self.actions = TerranActions()
        self.centered_on_base = False

    def done(self, observations: Observations) -> bool:
        return self.centered_on_base

    def execute(self, observations: Observations) -> actions.FunctionCall:
        if not self.centered_on_base:
            unit_y, unit_x = self.base_location.base_location_on_minimap()
            target = [unit_x, unit_y]
            self.centered_on_base = True
            return self.actions.move_camera(target)
        return self.actions.no_op()
Exemple #5
0
class SCVCommonActions:
    def __init__(self):
        self.actions = TerranActions()
        self.action_ids = TerranActionIds()
        self.unit_type_ids = UnitTypeIds()

    def select_a_group_of_scv(self, group_id: int) -> actions.FunctionCall:
        return self.actions.select_control_group(group_id)

    def send_scv_to_mineral(
            self, observations: Observations) -> actions.FunctionCall:
        if self.action_ids.harvest_gather() in observations.available_actions(
        ):
            unit_type = observations.screen().unit_type()
            unit_y, unit_x = (unit_type == self.unit_type_ids.
                              neutral_mineral_field()).nonzero()
            if unit_y.any():
                i = random.randint(0, len(unit_y) - 1)
                m_x = unit_x[i]
                m_y = unit_y[i]
                target = [int(m_x), int(m_y)]
                return self.actions.harvest_gather(target)
        return self.actions.no_op()

    def send_selected_scv_group_to_refinery(
            self, location: Location, observations: Observations,
            refinery_id: int) -> actions.FunctionCall:
        if self.action_ids.harvest_gather() in observations.available_actions(
        ):
            if refinery_id == 1:
                difference_from_cc = BuildingPositionsFromCommandCenter(
                ).vespene_geysers()[0]
            else:
                difference_from_cc = BuildingPositionsFromCommandCenter(
                ).vespene_geysers()[1]
            cc_y, cc_x = location.command_center_first_position()
            target = location.transform_distance(
                round(cc_x.mean()),
                difference_from_cc[0],
                round(cc_y.mean()),
                difference_from_cc[1],
            )
            #print("send collector " + str(refinery_id) + " to refinery " + str(target[0]) + " " + str(target[1]))
            return self.actions.harvest_gather(target)
        return self.actions.no_op()
Exemple #6
0
class MoveCameraOnMinimapTarget(Order):
    def __init__(self, base_location, minimap_target_x: int,
                 minimap_target_y: int):
        Order.__init__(self)
        self.base_location = base_location
        self.actions = TerranActions()
        self.camera_moved = False
        self.minimap_target_x = minimap_target_x
        self.minimap_target_y = minimap_target_y

    def done(self, observations: Observations) -> bool:
        return self.camera_moved

    def execute(self, observations: Observations) -> actions.FunctionCall:
        if not self.camera_moved:
            target = [self.minimap_target_x, self.minimap_target_y]
            self.camera_moved = True
            return self.actions.move_camera(target)
        return self.actions.no_op()
Exemple #7
0
class NoOrder(Order):

    is_done = False
    actions = None

    def __init__(self):
        Order.__init__(self)
        self.actions = TerranActions()

    def done(self, observations: Observations):
        return self.is_done

    def execute(self, obs: Observations):
        self.is_done = True
        return self.actions.no_op()
Exemple #8
0
 def do_nothing(self) -> actions.FunctionCall:
     return TerranActions().no_op()
Exemple #9
0
 def __init__(self):
     self.actions = TerranActions()
     self.action_ids = TerranActionIds()
     self.unit_type_ids = UnitTypeIds()
Exemple #10
0
 def __init__(self, location: Location):
     Order.__init__(self)
     self.location = location
     self.actions = TerranActions()
     self.action_ids = TerranActionIds()
     self.unit_type_ids = UnitTypeIds()
Exemple #11
0
 def __init__(self):
     Order.__init__(self)
     self.actions = TerranActions()
Exemple #12
0
 def __init__(self, base_location):
     Order.__init__(self)
     self.base_location = base_location
     self.actions = TerranActions()
     self.centered_on_base = False