def find_base_to_build_spinecrawler(self, bases):
     d_max = -1  # find base furthest to born position
     tag = None
     for base_tag in bases:
         if bases[base_tag].unit.float_attr.build_progress < 1:
             continue
         worker_num = self.assigned_harvesters(bases[base_tag])
         d = dist_to_pos(bases[base_tag].unit, self.born_pos)
         if worker_num > 0 and d > d_max:
             tag = base_tag
             d_max = d
     return tag
 def find_base_to_build(self, bases):
     d_min = 1000  # find base closed to born position
     tag = None
     for base_tag in bases:
         if bases[base_tag].unit.float_attr.build_progress < 1:
             continue
         worker_num = self.assigned_harvesters(bases[base_tag])
         d = dist_to_pos(bases[base_tag].unit, self.born_pos)
         if worker_num > 0 and d < d_min:
             tag = base_tag
             d_min = d
     return tag
 def find_base_pos(self, dc):
     areas = dc.dd.base_pool.resource_cluster
     bases = [
         unit for unit in self.obs['units'] if unit.unit_type in BASE_UNITS
     ]
     d_min = 10000
     pos = None
     for area in areas:
         dist = [dist_to_pos(base, area.ideal_base_pos) for base in bases]
         if min(dist) > 5:  # area do not have a base now
             d = dc.dd.base_pool.home_dist[area]
             if 5 < d < d_min:
                 pos = area.ideal_base_pos
                 d_min = d
     return pos
Exemplo n.º 4
0
 def exe_rock(self, squad, pos):
     actions = []
     rocks = [
         u for u in self.dc.sd.obs['units'] if u.int_attr.unit_type ==
         UNIT_TYPEID.NEUTRAL_DESTRUCTIBLEROCKEX1DIAGONALHUGEBLUR.value
     ]
     target_rock = None
     for r in rocks:
         d = geom.dist_to_pos(r, (pos['x'], pos['y']))
         if d < 0.1:
             target_rock = r
             break
     for u in squad.units:
         actions.append(self.micro_mgr.attack_target(u, target_rock))
     return actions
 def find_base_pos_aggressive(self, dc):
     bases = [
         unit for unit in self.obs['units'] if unit.unit_type in BASE_UNITS
     ]
     if len(dc.dd.base_pool.bases) < 4:
         sorted_area = sorted(dc.dd.base_pool.home_dist.items(),
                              key=operator.itemgetter(1))
     else:
         sorted_area = sorted(dc.dd.base_pool.enemy_home_dist.items(),
                              key=operator.itemgetter(1))
         sorted_area = sorted_area[4:]
     sorted_pos_list = [x[0].ideal_base_pos for x in sorted_area]
     for area_pos in sorted_pos_list:
         dist = [dist_to_pos(base, area_pos) for base in bases]
         if min(dist) > 5:  # area do not have a base now
             return area_pos
     return None
Exemplo n.º 6
0
def find_nearest_to_pos(units, pos):
    """ find the nearest one to pos within the list 'units' """
    if not units:
        return None
    dd = np.asarray([dist_to_pos(u, pos) for u in units])
    return units[dd.argmin()]