def build_reaper(self, obs):
        new_action = [actions.FUNCTIONS.no_op()]

        if self.reqSteps == 0:
            self.reqSteps = 4

        if self.reqSteps == 4:
            new_action = HelperClass.select_all_buildings(obs)

        if self.reqSteps == 3:
            if len(obs.observation.multi_select > 0):
                for i in range(len(obs.observation.multi_select)):
                    if obs.observation.multi_select[i].unit_type == units.Terran.Barracks or \
                            obs.observation.multi_select[i].unit_type == units.Terran.BarracksTechLab or \
                            obs.observation.multi_select[i].unit_type == units.Terran.BarracksReactor:
                        new_action = [
                            actions.FUNCTIONS.select_unit(
                                "select_all_type", i)
                        ]
                        break

        if self.reqSteps == 2:
            if HelperClass.is_unit_selected(self, obs, units.Terran.Barracks) or \
                    HelperClass.is_unit_selected(self, obs, units.Terran.BarracksTechLab) or \
                    HelperClass.is_unit_selected(self, obs, units.Terran.BarracksReactor):
                if HelperClass.do_action(
                        self, obs, actions.FUNCTIONS.Train_Reaper_quick.id):
                    new_action = [actions.FUNCTIONS.Train_Reaper_quick("now")]

        # One step is being intentionally left blank.
        self.reqSteps -= 1
        ActionSingleton().set_action(new_action)
Ejemplo n.º 2
0
    def build_tech_lab_barracks(self, obs):
        """
            Builds a tech lab addon at a barracks.
        """
        new_action = [actions.FUNCTIONS.no_op()]
        barracks = HelperClass.get_units(self, obs, units.Terran.Barracks)

        if self.reqSteps == 0:
            self.reqSteps = 4

        elif self.reqSteps == 4:
            new_action = [actions.FUNCTIONS.move_camera(self.base_location)]

        elif self.reqSteps == 3:
            if len(barracks) > 0 and HelperClass.not_in_progress(
                    self, obs, units.Terran.Barracks):
                new_action = [
                    actions.FUNCTIONS.select_point(
                        "select", (HelperClass.sigma(
                            barracks[0].x), HelperClass.sigma(barracks[0].y)))
                ]
        elif self.reqSteps == 2:
            if len(barracks) > 0:
                if HelperClass.is_unit_selected(self, obs,
                                                units.Terran.Barracks):
                    if HelperClass.do_action(
                            self, obs,
                            actions.FUNCTIONS.Build_TechLab_Barracks_quick.id):
                        new_action = [
                            actions.FUNCTIONS.Build_TechLab_Barracks_quick(
                                "now")
                        ]
        self.reqSteps -= 1
        ActionSingleton().set_action(new_action)
Ejemplo n.º 3
0
    def transform_vikings_to_air(self, obs):
        """ Transforms all available Vikings to their air mode (Fighter mode)
                :param obs: The observer.
        """
        new_action = [actions.FUNCTIONS.no_op()]
        if self.reqSteps == 0:
            self.reqSteps = 4

        if self.reqSteps == 4:
            if actions.FUNCTIONS.select_army.id in obs.observation.available_actions:
                new_action = [actions.FUNCTIONS.select_army("select")]

        if self.reqSteps == 3:
            vikings_ground = [
                vikings for vikings in obs.observation.multi_select
                if vikings.unit_type == units.Terran.VikingAssault
            ]
            if len(vikings_ground) > 0:
                if HelperClass.do_action(self, obs,
                                         actions.FUNCTIONS.select_unit.id):
                    for i in range(len(obs.observation.multi_select)):
                        if obs.observation.multi_select[
                                i].unit_type == units.Terran.VikingAssault:
                            new_action = [
                                actions.FUNCTIONS.select_unit(
                                    "select_all_type", i)
                            ]
                            break

        if self.reqSteps == 2:
            if HelperClass.do_action(
                    self, obs,
                    actions.FUNCTIONS.Morph_VikingFighterMode_quick.id):
                new_action = [
                    actions.FUNCTIONS.Morph_VikingFighterMode_quick("now")
                ]
                self.action_finished = True

        # One step is being intentionally left blank.
        self.reqSteps -= 1
        ActionSingleton().set_action(new_action)
Ejemplo n.º 4
0
    def expand(self, obs):
        """
            Builds a command center at a suitable, empty base. Doesn't build in the main bases.
        """
        new_action = [actions.FUNCTIONS.no_op()]
        if self.reqSteps == 0:
            self.expo_loc = 0
            self.reqSteps = 4

        if self.reqSteps == 4:  # move to base
            new_action = [HelperClass.move_camera_to_base_location(self, obs)]

        if self.reqSteps == 3:  # select scv
            command_scv = HelperClass.get_units(self, obs, units.Terran.SCV)
            if len(command_scv) > 0 and not HelperClass.is_unit_selected(
                    self, obs, units.Terran.SCV):
                if (obs.observation.player.idle_worker_count > 0):
                    new_action = [
                        actions.FUNCTIONS.select_idle_worker(
                            "select", obs, units.Terran.SCV)
                    ]
                else:
                    command = random.choice(command_scv)
                    new_action = [
                        actions.FUNCTIONS.select_point(
                            "select", (HelperClass.sigma(
                                command.x), HelperClass.sigma(command.y)))
                    ]

        # This part finds a vacant expansion location
        if self.reqSteps == 2:
            camera_pos = HelperClass.get_current_minimap_location(obs)
            if self.start_top is not None and not self.start_top:
                expansions_minimap = Coordinates.EXPO_LOCATIONS2
                expansions_screen = Coordinates.CC_LOCATIONS2
            else:
                expansions_minimap = Coordinates.EXPO_LOCATIONS
                expansions_screen = Coordinates.CC_LOCATIONS
            # This should be compatible with the coordinates gotten from raw_units
            expansions_relative_screen = [
                ((a[0][0] - camera_pos[0]) * (200 * 84 / (24 * 64)) + a[1][0],
                 (a[0][1] - camera_pos[1]) * (200 * 84 / (24 * 64)) + a[1][1])
                for a in list(zip(expansions_minimap, expansions_screen))
            ]

            cc = [
                u for u in obs.observation.raw_units
                if (u.unit_type == units.Terran.CommandCenter
                    or u.unit_type == units.Terran.OrbitalCommand
                    or u.unit_type == units.Terran.PlanetaryFortress)
            ]

            for i in range(len(expansions_relative_screen)):
                if len(cc) > 0:
                    vacant = True
                    for j in range(len(cc)):
                        # 10 is an arbitrary screen length.
                        if (abs(cc[j].x - expansions_relative_screen[i][0]) <
                                10 and
                                abs(cc[j].y - expansions_relative_screen[i][1])
                                < 10):
                            vacant = False
                            break
                    if vacant:
                        new_action = [
                            actions.FUNCTIONS.move_camera(
                                expansions_minimap[i])
                        ]
                        self.expo_loc = i
                        break

        if self.reqSteps == 1:
            if self.expo_loc is not None:
                if self.start_top:
                    t = Coordinates.CC_LOCATIONS[self.expo_loc]
                else:
                    t = Coordinates.CC_LOCATIONS2[self.expo_loc]
                if HelperClass.do_action(
                        self, obs,
                        actions.FUNCTIONS.Build_CommandCenter_screen.id):
                    new_action = HelperClass.place_building(
                        self, obs, units.Terran.CommandCenter, t[0], t[1])

                self.expo_loc = None

        self.reqSteps -= 1
        ActionSingleton().set_action(new_action)
Ejemplo n.º 5
0
    def return_scv(self, obs):
        """
            Returns an idle SCV to mining. It tries to populate refineries first. Checks other bases if the main base
            has depleted its resources.
        """
        new_action = [actions.FUNCTIONS.no_op()]
        if self.reqSteps == 0:
            self.reqSteps = 4

        if self.reqSteps == 4:
            if obs.observation.player.idle_worker_count > 0:
                new_action = [
                    actions.FUNCTIONS.select_idle_worker(
                        "select", obs, units.Terran.SCV)
                ]

        # Finds a suitable base to send the SCV to.
        if self.reqSteps == 3:
            command_centers = [
                u for u in obs.observation.raw_units if u.alliance == 1
                and u.unit_type == units.Terran.CommandCenter
                and u.build_progress == 100 and u.ideal_harvesters > 0
            ]
            undermanned_command_centers = [
                u for u in command_centers
                if u.assigned_harvesters / u.ideal_harvesters < 0
            ]
            undermanned_refineries = [
                u for u in obs.observation.raw_units
                if u.alliance == 1 and u.unit_type == units.Terran.Refinery
                and u.build_progress == 100 and u.assigned_harvesters < 3
            ]
            if len(undermanned_refineries) > 0:
                refinery = random.choice(undermanned_refineries)
                new_action = HelperClass.move_screen(obs,
                                                     (refinery.x, refinery.y))
            elif len(undermanned_command_centers) > 0:
                command_center = random.choice(undermanned_command_centers)
                new_action = HelperClass.move_screen(
                    obs, (command_center.x, command_center.y))
            elif len(command_centers) > 0:
                command_center = random.choice(command_centers)
                new_action = HelperClass.move_screen(
                    obs, (command_center.x, command_center.y))

        # Should be at a base now.
        if self.reqSteps == 2:
            undermanned_refineries = [
                u for u in obs.observation.feature_units
                if u.alliance == 1 and u.unit_type == units.Terran.Refinery
                and u.build_progress == 100 and u.assigned_harvesters < 3
            ]
            minerals = [
                u for u in obs.observation.feature_units
                if (u.unit_type == units.Neutral.MineralField
                    or u.unit_type == units.Neutral.MineralField750
                    or u.unit_type == units.Neutral.RichMineralField
                    or u.unit_type == units.Neutral.RichMineralField750)
            ]
            if len(undermanned_refineries) > 0:
                refinery = undermanned_refineries[0]
                if HelperClass.do_action(
                        self, obs, actions.FUNCTIONS.Harvest_Gather_screen.id):
                    new_action = [
                        actions.FUNCTIONS.Harvest_Gather_screen(
                            "now", (HelperClass.sigma(
                                refinery.x), HelperClass.sigma(refinery.y)))
                    ]
                    self.action_finished = True
            elif len(minerals) > 0:
                mineral = minerals[0]
                if HelperClass.do_action(
                        self, obs, actions.FUNCTIONS.Harvest_Gather_screen.id):
                    new_action = [
                        actions.FUNCTIONS.Harvest_Gather_screen(
                            "now", (HelperClass.sigma(
                                mineral.x), HelperClass.sigma(mineral.y)))
                    ]
                    self.action_finished = True

        # There's one step left (reqSteps == 1) that's intentionally being left blank.
        self.reqSteps -= 1

        ActionSingleton().set_action(new_action)