Exemple #1
0
 def _select_a_new_vcs_from_all_group(
         self, observations: Observations) -> actions.FunctionCall:
     if self.action_ids.select_unit() in observations.available_actions():
         self.step = self.step + 1
         action = self.actions.select_unit(self.scv_index_in_all_group)
         self.scv_index_in_all_group = self.scv_index_in_all_group + 1
         return action
Exemple #2
0
 def _research_concussive_shells(
         self, observations: Observations) -> actions.FunctionCall:
     if self.action_ids.research_concussive_shells(
     ) in observations.available_actions():
         self.step = self.step + 1
         return self.actions.research_concussive_shells()
     return self.actions.no_op()
Exemple #3
0
 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
 def _research_combat_shield(
         self, observations: Observations) -> actions.FunctionCall:
     if self.action_ids.research_combat_shield(
     ) in observations.available_actions():
         self.step = self.step + 1
         return self.actions.research_combat_shield()
     return self.actions.no_op()
Exemple #5
0
 def execute(self, observations: Observations) -> actions.FunctionCall:
     if not self.building_built:
         if self.build_action_id() in observations.available_actions():
             unit_y, unit_x = self.base_location.locate_command_center(
                 observations.screen())
             if unit_x.any():
                 target = self.base_location.transform_distance(
                     int(unit_x.mean()), self.x_from_base,
                     int(unit_y.mean()), self.y_from_base)
                 self.building_built = True
                 return self.build_action(target)
         elif not self.select_scv_order.done(observations):
             return self.select_scv_order.execute(observations)
     elif not self.building_rallied:
         if not self.building_selected:
             unit_type = observations.screen().unit_type()
             unit_y, unit_x = (unit_type == self.building_type()).nonzero()
             if unit_y.any():
                 target = [int(unit_x.mean()), int(unit_y.mean())]
                 self.building_selected = True
                 return self.actions.select_point(target)
         else:
             self.building_rallied = True
             if self.base_location.command_center_is_top_left():
                 target = [29, 21]
             else:
                 target = [29, 46]
             return self.actions.rally_units_minimap(target)
     return self.actions.no_op()
Exemple #6
0
 def execute(self, observations: Observations) -> actions.FunctionCall:
     if self.done(observations):
         self._reset()
     elif not self.army_selected:
         if self.action_ids.select_army() in observations.available_actions(
         ):
             self.army_selected = True
             return self.actions.select_army()
     elif self.army_selected and self.action_ids.attack_minimap(
     ) in observations.available_actions():
         self.push_ordered = True
         if self.base_location.command_center_is_top_left():
             target = [39, 45]
         else:
             target = [21, 24]
         return self.actions.attack_minimap(target)
     return self.actions.no_op()
Exemple #7
0
 def execute(self, observations: Observations) -> actions.FunctionCall:
     if not self.select_scv_order.done(observations):
         return self.select_scv_order.execute(observations)
     elif self.action_ids.move_screen() in observations.available_actions():
         unit_type = observations.screen().unit_type()
         unit_y, unit_x = (
             unit_type == self.unit_type_ids.terran_refinery()).nonzero()
         if unit_y.any():
             target = [int(unit_x.mean()), int(unit_y.mean())]
             self.scv_sent_to_refinery = True
             return self.actions.move_screen(target)
     return self.actions.no_op()
Exemple #8
0
 def execute(self, observations: Observations) -> actions.FunctionCall:
     if not self.supply_depot_built:
         if not self.select_scv_order.done(observations):
             return self.select_scv_order.execute(observations)
         elif self.action_ids.build_supply_depot(
         ) in observations.available_actions():
             cc_y, cc_x = self.base_location.locate_command_center(
                 observations.screen())
             target = self.base_location.transform_distance(
                 int(cc_x.mean()), self.x_from_base, int(cc_y.mean()),
                 self.y_from_base)
             self.supply_depot_built = True
             return self.actions.build_supply_depot(target)
     return self.actions.no_op()
Exemple #9
0
 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()
Exemple #10
0
    def execute(self, observations: Observations) -> actions.FunctionCall:
        if not self.builder_scv_selected:
            self.builder_scv_selected = True
            print("select builder")
            return SelectSCV(self.base_location).execute(observations)
        # https://itnext.io/how-to-locate-and-select-units-in-pysc2-2bb1c81f2ad3
        elif not self.refinery_building and self.action_ids.build_refinery(
        ) in observations.available_actions():
            unit_type = observations.screen().unit_type()
            vespene_y, vespene_x = (unit_type == self.unit_type_ids.
                                    neutral_vespene_geyser()).nonzero()
            vespene_geyser_count = int(math.ceil(len(vespene_y) / 97))
            units = []
            for i in range(0, len(vespene_y)):
                units.append((vespene_x[i], vespene_y[i]))
            kmeans = KMeans(vespene_geyser_count)
            kmeans.fit(units)
            vespene1_x = int(kmeans.cluster_centers_[0][0])
            vespene1_y = int(kmeans.cluster_centers_[0][1])
            self.refinery_target = [vespene1_x, vespene1_y]
            self.refinery_building = True
            print("refinery building")
            return self.actions.build_refinery(self.refinery_target)
        elif self.refinery_building and not self.refinery_selected:
            unit_type = observations.screen().unit_type()
            refinery_y, refinery_x = (
                unit_type == self.unit_type_ids.terran_refinery()).nonzero()
            if refinery_y.any():
                self.refinery_selected = True
                print("refinery selected")
                return self.actions.select_point(self.refinery_target)
        elif self.refinery_selected and not self.first_collector_scv_selected:
            if observations.single_select().is_built():
                self.first_collector_scv_selected = True
                print("select first collector")
                return SelectSCV(self.base_location).execute(observations)
        elif self.first_collector_scv_selected and not self.first_collector_scv_sent:
            self.first_collector_scv_sent = True
            print("sent first collector")
            return self.actions.harvest_gather(self.refinery_target)
        elif self.first_collector_scv_sent and not self.second_collector_scv_selected:
            self.second_collector_scv_selected = True
            print("select second collector")
            return SelectSCV(self.base_location).execute(observations)
        elif self.second_collector_scv_selected and not self.second_collector_scv_sent:
            self.second_collector_scv_sent = True
            print("sent second collector")
            return self.actions.harvest_gather(self.refinery_target)

        return self.actions.no_op()
Exemple #11
0
 def execute(self, observations: Observations) -> actions.FunctionCall:
     if not self.command_center_selected:
         unit_type = observations.screen().unit_type()
         center_y, center_x = (unit_type == self.unit_type_ids.
                               terran_command_center()).nonzero()
         center_x = round(center_x.mean())
         center_y = round(center_y.mean())
         target = [center_x, center_y]
         self.command_center_selected = True
         return self.actions.select_point(target)
     elif self.command_center_selected and self.action_ids.morph_orbital_command(
     ) in observations.available_actions():
         self.orbital_command_built = True
         return self.actions.morph_orbital_command()
     return self.actions.no_op()
Exemple #12
0
 def _build_reactor(self,
                    observations: Observations) -> actions.FunctionCall:
     if self.action_ids.build_reactor_barracks(
     ) in observations.available_actions():
         self.step = self.step + 1
         cc_y, cc_x = self.location.command_center_first_position()
         difference_from_cc = self.difference_from_command_center()
         target = self.location.transform_distance(
             round(cc_x.mean()),
             difference_from_cc[0],
             round(cc_y.mean()),
             difference_from_cc[1],
         )
         return self.actions.build_reactor_barracks(target)
     return self.actions.no_op()
Exemple #13
0
    def attack_minimap(self, observations: Observations) -> actions.FunctionCall:
        do_it = True
        if not observations.single_select().empty() and observations.single_select().unit_type() == self.unit_type_ids.terran_scv():
            do_it = False
        if not observations.multi_select().empty() and observations.multi_select().unit_type(0) == self.unit_type_ids.terran_scv():
            do_it = False

        if do_it and self.action_ids.attack_minimap() in observations.available_actions():
            x_offset = random.randint(-1, 1)
            y_offset = random.randint(-1, 1)
            target = self.location.transform_location(int(self.x) + (x_offset * 8), int(self.y) + (y_offset * 8))

            return self.actions.attack_minimap(target)

        return self.actions.no_op()
Exemple #14
0
 def execute(self, observations: Observations) -> actions.FunctionCall:
     if self.done(observations):
         self._reset()
     elif self._train_action_id() in observations.available_actions():
         self.already_trained = self.already_trained + 1
         return self._train_action()
     elif not self.barracks_selected:
         unit_type = observations.screen().unit_type()
         unit_y, unit_x = (
             unit_type == self.unit_type_ids.terran_barracks()).nonzero()
         if unit_y.any():
             target = [int(unit_x.mean()), int(unit_y.mean())]
             self.barracks_selected = True
             return self.actions.select_point(target)
     return self.actions.no_op()
Exemple #15
0
 def _build_factory(self,
                    observations: Observations) -> actions.FunctionCall:
     cc_y, cc_x = self.location.command_center_first_position()
     factories_count = BuildingCounter().factories_count(observations)
     if factories_count < self.max_factories and self.action_ids.build_factory(
     ) in observations.available_actions():
         if cc_y.any():
             current_count_to_difference_from_cc = BuildingPositionsFromCommandCenter(
             ).factories()
             target = self.location.transform_distance(
                 round(cc_x.mean()),
                 current_count_to_difference_from_cc[factories_count][0],
                 round(cc_y.mean()),
                 current_count_to_difference_from_cc[factories_count][1],
             )
             return self.actions.build_factory(target)
     return self.actions.no_op()
Exemple #16
0
    def execute(self, observations: Observations) -> actions.FunctionCall:
        if not self.barracks_selected:
            unit_type = observations.screen().unit_type()
            unit_y, unit_x = (
                unit_type == self.unit_type_ids.terran_barracks()).nonzero()
            target = [int(unit_x.mean()), int(unit_y.mean())]
            self.barracks_selected = True
            return self.actions.select_point(target)
        elif self.action_ids.build_techlab_barracks(
        ) in observations.available_actions():
            self.tech_lab_built = True
            unit_type = observations.screen().unit_type()
            unit_y, unit_x = (
                unit_type == self.unit_type_ids.terran_barracks()).nonzero()
            target = [int(unit_x.mean()), int(unit_y.mean())]
            return self.actions.build_techlab_barracks(target)

        return self.actions.no_op()
Exemple #17
0
 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 #18
0
    def _build_refinery(self,
                        observations: Observations) -> actions.FunctionCall:
        if self.action_ids.build_refinery() in observations.available_actions(
        ):
            if self.refinery_index == 1:
                difference_from_cc = BuildingPositionsFromCommandCenter(
                ).vespene_geysers()[0]
            else:
                difference_from_cc = BuildingPositionsFromCommandCenter(
                ).vespene_geysers()[1]
            cc_y, cc_x = self.location.command_center_first_position()
            target = self.location.transform_distance(
                round(cc_x.mean()),
                difference_from_cc[0],
                round(cc_y.mean()),
                difference_from_cc[1],
            )
            #print(
            #    "build refinery "+str(self.refinery_index) + " on "+str(target[0])+ " "+str(target[1])
            #    + " CC is "+ str(round(cc_x.mean())) + " " + str(round(cc_y.mean()))
            #)

            return self.actions.build_refinery(target)
        return self.actions.no_op()
Exemple #19
0
    def select_army(self, observations: Observations) -> actions.FunctionCall:
        if self.action_ids.select_army() in observations.available_actions():
            return self.actions.select_army()

        return self.actions.no_op()
Exemple #20
0
 def train_marine(self, observations: Observations) -> actions.FunctionCall:
     if self.action_ids.train_marauder() in observations.available_actions(
     ):
         return self.actions.train_marauder()
     return self.actions.no_op()
Exemple #21
0
 def _train_scv(self, observations: Observations) -> actions.FunctionCall:
     if self.action_ids.train_scv() in observations.available_actions():
         return self.actions.train_scv()
     return self.actions.no_op()
Exemple #22
0
 def executable(self, observations: Observations) -> bool:
     return self.action_ids.select_army() in observations.available_actions(
     )