Ejemplo n.º 1
0
    def _command_army_onewave(self, cmd_queue):
        enemy_pool = self._dc.dd.enemy_pool

        # rally
        if self._rally_pos is None:
            self._rally_pos = self._get_rally_pos()
        for squad in self._army.squads:
            if squad.status == SquadStatus.IDLE or squad.status == SquadStatus.MOVE:
                squad.status = SquadStatus.MOVE
                cmd = CombatCommand(type=CombatCmdType.MOVE,
                                    squad=squad,
                                    position=self._rally_pos)
                cmd_queue.push(cmd)
                self._cmds.append(cmd)

        # attack
        rallied_squads = [
            squad for squad in self._army.squads
            if self._distance(squad.centroid, self._rally_pos) < 8
        ]
        if not self._ready_to_go and len(rallied_squads) >= 4:
            self._ready_to_go = True
        if self._ready_to_go and enemy_pool.weakest_cluster is not None:
            attacking_squads = [
                squad for squad in self._army.squads
                if squad.status == SquadStatus.ATTACK
            ]
            for squad in rallied_squads + attacking_squads:
                squad.status = SquadStatus.ATTACK
                cmd = CombatCommand(
                    type=CombatCmdType.ATTACK,
                    squad=squad,
                    position=enemy_pool.weakest_cluster.centroid)
                cmd_queue.push(cmd)
                self._cmds.append(cmd)
Ejemplo n.º 2
0
    def _command_army_zerg6zerg(self, cmd_queue):
        enemy_pool = self._dc.dd.enemy_pool
        enemy_combat_units = self._find_enemy_combat_units(enemy_pool.units)
        if len(enemy_combat_units) == 0 or enemy_pool.closest_cluster is None:
            return False
        bases = self._dc.dd.base_pool.bases

        if len(bases) <= 2:
            enemy_attacking_me = False
            for tag in bases:
                b = bases[tag].unit
                for e in enemy_combat_units:
                    if self._cal_square_dist(e, b) < 60:
                        enemy_attacking_me = True
                        break
                if enemy_attacking_me:
                    break

            second_base_pos = self._get_second_base_pos()
            defend_base_pos = self._get_main_base_pos() \
              if second_base_pos is None else second_base_pos

            if enemy_attacking_me:
                squad = self._create_zergling_squads()
                squad.status = SquadStatus.MOVE

                closest_enemy = self._find_closest_enemy_to_pos(
                    squad.centroid, enemy_combat_units)

                cmd = CombatCommand(type=CombatCmdType.MOVE,
                                    squad=squad,
                                    position=self._get_zergling_6pos(
                                        closest_enemy, defend_base_pos))

                cmd_queue.push(cmd)
                self._cmds.append(cmd)
                return True
            else:
                squad = self._create_zergling_squads()
                squad.status = SquadStatus.MOVE

                cmd = CombatCommand(type=CombatCmdType.MOVE,
                                    squad=squad,
                                    position=defend_base_pos)

                cmd_queue.push(cmd)
                self._cmds.append(cmd)

                return False

        return False
Ejemplo n.º 3
0
 def _command_army_economy_first(self, cmd_queue):
     enemy_pool = self._dc.dd.enemy_pool
     if len(self._army.squads) >= 5 and len(enemy_pool.enemy_clusters) >= 1:
         for squad in self._army.squads:
             cmd = CombatCommand(
                 type=CombatCmdType.ATTACK,
                 squad=squad,
                 position=enemy_pool.weakest_cluster.centroid)
             cmd_queue.push(cmd)
             self._cmds.append(cmd)
Ejemplo n.º 4
0
    def _command_army_atk_stone(self, cmd_queue):
        if self._dc.sd.obs['player'][3] < 70:
            return False

        rocks = [
            u for u in self._dc.sd.obs['units'] if u.int_attr.unit_type ==
            UNIT_TYPEID.NEUTRAL_DESTRUCTIBLEROCKEX1DIAGONALHUGEBLUR.value
        ]
        home_pos = {
            'x': self._dc.dd.base_pool.home_pos[0],
            'y': self._dc.dd.base_pool.home_pos[1]
        }

        if len(rocks) > 1:
            r0_pos = {
                'x': rocks[0].float_attr.pos_x,
                'y': rocks[0].float_attr.pos_y
            }
            r1_pos = {
                'x': rocks[1].float_attr.pos_x,
                'y': rocks[1].float_attr.pos_y
            }
            if self._distance(r0_pos, home_pos) > self._distance(
                    r1_pos, home_pos):
                enemy_rock = rocks[0]
            else:
                enemy_rock = rocks[1]
        else:
            return False

        if self._verbose > 0:
            print('Attack rock.')
        for squad in self._army.squads:
            if squad.uniform is not None:
                continue
            if squad.status == SquadStatus.SCOUT:
                continue
            squad.status = SquadStatus.ROCK
            cmd = CombatCommand(type=CombatCmdType.ROCK,
                                squad=squad,
                                position={
                                    'x': enemy_rock.float_attr.pos_x,
                                    'y': enemy_rock.float_attr.pos_y
                                })
            cmd_queue.push(cmd)
            self._cmds.append(cmd)
        return True
Ejemplo n.º 5
0
    def _mutalisk_harass(self, cmd_queue, mutalisk_uniform,
                         harass_station_pos1, harass_station_pos2):
        enemy_units = self._dc.dd.enemy_pool.units
        enemy_buildings_and_drones_overlords = [
            e for e in enemy_units if e.int_attr.unit_type in BUILDING_UNITS
            or e.int_attr.unit_type in [
                UNIT_TYPEID.ZERG_OVERLORD.value, UNIT_TYPEID.ZERG_DRONE.value,
                UNIT_TYPEID.ZERG_OVERSEER.value
            ]
        ]

        for squad in self._army.squads:
            if squad.uniform == mutalisk_uniform and \
                    squad.combat_status == MutaliskSquadStatus.IDLE:
                # rally at a safe corner
                cmd = CombatCommand(
                    type=CombatCmdType.ATTACK,  # for defend
                    squad=squad,
                    position=harass_station_pos1)
                cmd_queue.push(cmd)
                self._cmds.append(cmd)

        rallied_mutalisk_squads = [
            squad for squad in self._army.squads
            if squad.uniform == mutalisk_uniform
            and self._distance(squad.centroid, harass_station_pos1) < 5
        ]
        if len(rallied_mutalisk_squads) > 0:
            rallied_mutalisk_squads[
                0].combat_status = MutaliskSquadStatus.PHASE1

        for squad in self._army.squads:
            if squad.uniform == mutalisk_uniform and \
                    squad.combat_status == MutaliskSquadStatus.PHASE1:
                cmd = CombatCommand(type=CombatCmdType.MOVE,
                                    squad=squad,
                                    position=harass_station_pos2)
                cmd_queue.push(cmd)
                self._cmds.append(cmd)

        rallied_mutalisk_squads = [
            squad for squad in self._army.squads
            if squad.uniform == mutalisk_uniform
            and self._distance(squad.centroid, harass_station_pos2) < 5
        ]
        if len(rallied_mutalisk_squads) > 0:
            rallied_mutalisk_squads[
                0].combat_status = MutaliskSquadStatus.PHASE2

        if len(enemy_buildings_and_drones_overlords) == 0:
            return None
        for squad in self._army.squads:
            if squad.uniform == mutalisk_uniform and \
                    squad.combat_status == MutaliskSquadStatus.PHASE2:
                closest_enemy_base = self._find_closest_enemy_to_pos(
                    squad.centroid, enemy_buildings_and_drones_overlords)
                cmd = CombatCommand(type=CombatCmdType.ATTACK,
                                    squad=squad,
                                    position={
                                        'x':
                                        closest_enemy_base.float_attr.pos_x,
                                        'y':
                                        closest_enemy_base.float_attr.pos_y
                                    })
                cmd_queue.push(cmd)
                self._cmds.append(cmd)
Ejemplo n.º 6
0
    def _command_army_reform(self, cmd_queue, food_trigger, retreat_food,
                             all_in):
        enemy_pool = self._dc.dd.enemy_pool
        self._food_trigger = food_trigger
        if retreat_food is None:
            retreat_food = self._food_trigger - 20

        # rally after production_strategy
        if not self._ready_to_go:
            if enemy_pool.closest_cluster is None:
                return None
            # print('rally')
            self._rally_pos = self._find_base_pos_in_danger(enemy_pool)
            if self._rally_pos is None:
                return None
            for squad in self._army.squads:
                if squad.uniform is not None and not all_in:
                    continue
                if squad.status == SquadStatus.SCOUT and not all_in:
                    continue
                squad.status = SquadStatus.MOVE

                cmd = CombatCommand(type=CombatCmdType.MOVE,
                                    squad=squad,
                                    position=self._rally_pos)
                cmd_queue.push(cmd)
                self._cmds.append(cmd)

            rallied_squads = [
                squad for squad in self._army.squads
                if self._distance(squad.centroid, self._rally_pos) < 10
            ]
            for squad in rallied_squads:
                if squad.uniform is not None and not all_in:
                    continue
                if squad.status == SquadStatus.SCOUT and not all_in:
                    continue
                squad.status = SquadStatus.IDLE
            if self._dc.sd.obs['player'][3] >= self._food_trigger and \
                    len(rallied_squads) >= 15:
                self._ready_to_go = True

        # rally before attack
        attack_pos = enemy_pool.priority_pos
        if attack_pos is None:
            if enemy_pool.closest_cluster is None:
                return None
            attack_pos = enemy_pool.closest_cluster.centroid

        if self._ready_to_go and not self._ready_to_attack:
            if enemy_pool.closest_cluster is None:
                return None
            # print('Ready to go and rally before attack')

            temp_pos = attack_pos
            for squad in self._army.squads:
                if squad.uniform is not None and not all_in:
                    continue
                if squad.status == SquadStatus.SCOUT and not all_in:
                    continue
                # safe dist
                if 25 < self._distance(
                        squad.centroid,
                        enemy_pool.closest_cluster.centroid) < 30:
                    self._rally_pos_for_attack = squad.centroid

            if (self._dc.sd.obs['player'][5] <
                    self._estimate_enemy_army_power()
                    or self._dc.sd.obs['player'][3] < retreat_food):
                if self._verbose > 0:
                    print('Retreat.')
                self._ready_to_go = False
                self._food_trigger += 20
                self._food_trigger = min(self._food_trigger, 195)

            for squad in self._army.squads:
                if squad.uniform is not None and not all_in:
                    continue
                if squad.status == SquadStatus.SCOUT and not all_in:
                    continue
                squad.status = SquadStatus.MOVE
                cmd = CombatCommand(
                    type=CombatCmdType.ATTACK,
                    squad=squad,
                    position=temp_pos if self._rally_pos_for_attack is None
                    else self._rally_pos_for_attack)
                cmd_queue.push(cmd)
                self._cmds.append(cmd)

            rallied_squads_for_attack = [squad for squad in self._army.squads
                                         if self._distance(
                squad.centroid, self._rally_pos_for_attack) < 8] \
              if (self._rally_pos_for_attack is not None) else []
            for squad in rallied_squads_for_attack:
                if squad.uniform is not None and not all_in:
                    continue
                if squad.status == SquadStatus.SCOUT and not all_in:
                    continue
                squad.status = SquadStatus.IDLE

            if len(rallied_squads_for_attack) >= 15:
                self._ready_to_attack = True

        # attack
        if self._ready_to_attack:
            if enemy_pool.closest_cluster is None:
                return None
            if self._verbose > 0:
                print('Attack')
            est_enemy_power = self._estimate_enemy_army_power()
            if (self._dc.sd.obs['player'][5] < est_enemy_power
                    or self._dc.sd.obs['player'][3] < retreat_food):
                if self._verbose > 0:
                    print('Retreat.')
                self._ready_to_attack = False
                self._ready_to_go = False
                self._food_trigger += 20
                self._food_trigger = min(self._food_trigger, 195)
                return None
            for squad in self._army.squads:
                if squad.uniform is not None and not all_in:
                    continue
                if squad.status == SquadStatus.SCOUT and not all_in:
                    continue
                squad.status = SquadStatus.ATTACK
                cmd = CombatCommand(type=CombatCmdType.ATTACK,
                                    squad=squad,
                                    position=attack_pos)
                cmd_queue.push(cmd)
                self._cmds.append(cmd)
Ejemplo n.º 7
0
    def _command_army_defend(self, cmd_queue):
        enemy_pool = self._dc.dd.enemy_pool
        enemy_combat_units = self._find_enemy_combat_units(enemy_pool.units)
        if len(enemy_combat_units) == 0 or enemy_pool.closest_cluster is None:
            return False
        bases = self._dc.dd.base_pool.bases

        if 2 < len(bases) <= 16:
            enemy_attacking_me = False
            for tag in bases:
                b = bases[tag].unit
                for e in enemy_combat_units:
                    if self._cal_square_dist(e, b) < 30:
                        enemy_attacking_me = True
                        closest_enemy = e
                        break
                if enemy_attacking_me:
                    break

            if enemy_attacking_me:
                if self._verbose > 0:
                    print('Defend.')
                for squad in self._army.squads + [self._create_queen_squads()]:
                    if squad.uniform is not None and \
                            squad.combat_status not in [MutaliskSquadStatus.IDLE,
                                                        MutaliskSquadStatus.PHASE1]:
                        continue
                    if squad.status == SquadStatus.SCOUT:
                        continue
                    squad.status = SquadStatus.MOVE
                    cmd = CombatCommand(type=CombatCmdType.ATTACK,
                                        squad=squad,
                                        position={
                                            'x':
                                            closest_enemy.float_attr.pos_x,
                                            'y': closest_enemy.float_attr.pos_y
                                        })
                    cmd_queue.push(cmd)
                    self._cmds.append(cmd)
                return True
        elif len(bases) <= 2:
            enemy_attacking_me = False
            for tag in bases:
                b = bases[tag].unit
                for e in enemy_combat_units:
                    if self._cal_square_dist(e, b) < 60:
                        enemy_attacking_me = True
                        # closest_enemy = e
                        break
                if enemy_attacking_me:
                    break

            if enemy_attacking_me:
                if self._verbose > 0:
                    print('Defend rush.')
                for squad in self._army.squads + [self._create_queen_squads()]:
                    if squad.uniform is not None and \
                            squad.combat_status not in [MutaliskSquadStatus.IDLE,
                                                        MutaliskSquadStatus.PHASE1]:
                        continue
                    if squad.status == SquadStatus.SCOUT:
                        continue
                    squad.status = SquadStatus.MOVE

                    second_base_pos = self._get_second_base_pos()
                    defend_base_pos = self._get_main_base_pos() \
                      if second_base_pos is None else second_base_pos

                    if squad.uniform == 'queen':
                        cmd = CombatCommand(type=CombatCmdType.ATTACK,
                                            squad=squad,
                                            position=self._get_slope_up_pos(
                                                defend_base_pos, 0.5))
                    else:
                        cmd = CombatCommand(type=CombatCmdType.ATTACK,
                                            squad=squad,
                                            position=self._get_slope_up_pos(
                                                defend_base_pos, 0.3))

                    cmd_queue.push(cmd)
                    self._cmds.append(cmd)
                return True
        # else:
        #     return False

        return False