示例#1
0
    def squared_dist(self, X, X2):
        """
        Returns the SCALED squared distance between X and X2.
        """
        length_scale = self.length_scale.abs().clamp(min=0.0, max=10.0)

        if X2 is None:
            dist = squared_distance(X / length_scale)
        else:
            dist = squared_distance(X / length_scale, X2 / length_scale)

        return dist
示例#2
0
    def get_refinery(self, geyser: Unit) -> Optional[Unit]:
        """ Returns: A refinery which is on top of unit `geyser` if any, None otherwise """
        for building in self.buildings[self.building.REFINERY]:
            if building.unit_type.is_refinery and util.squared_distance(
                    building.position, geyser.position) < 1:
                return building

        return None
示例#3
0
 def set_bases(self, bases, starting_base):
     """ takes a list of base obj  """
     for base in bases:
         self.set_potensial(
             base.position,
             util.squared_distance(starting_base.position, base.position))
         self.cache_base_pot[base.position] = self.get_potensial(
             base.position)
 def on_game_start(self):
     starting_base = self.agent.get_starting_base_location()
     base_locations = self.agent.base_location_manager.base_locations
     base_locations.sort(key=lambda base: -util.squared_distance(
         starting_base.position, base.position))
     for base_location in base_locations[:-3]:
         dict = {
             "base_location": base_location,
             "cord": base_location.position,
             "scouted": False,
             "dangerous": False,
         }
         self.scouted.append(dict)
     self.location_to_scout = self.scouted[0]
    def on_step(self):
        self.time = self.agent.time
        scouts = self.agent.get_scouts()
        if len(scouts) > 0:
            scout = scouts[0]

            if scout.hit_points < self.hp_last_step:
                self.location_to_scout["dangerous"] = True
            self.hp_last_step = scout.hit_points

            for dict in self.scouted:
                if util.squared_distance(scout.position, dict["cord"]) < 10:
                    dict["scouted"] = True
                if not dict["scouted"] and not dict["dangerous"]:
                    self.location_to_scout = dict
                    scout.move(dict["cord"])
                    break
            else:  # NOTE: no-break => set scouted to False for all.
                for dict in self.scouted:
                    dict["scouted"] = False
 def get_bases(self):
     """ returns all the base locations on the map  """
     starting_base = self.agent.get_starting_base_location()
     base_locations = self.agent.base_location_manager.base_locations
     base_locations.sort(key=lambda base: -util.squared_distance(starting_base.position, base.position))
     return base_locations
示例#7
0
 def is_collecting_gas(self, agent):
     """ Returns: True if Worker is collecting gas, False otherwise """
     for refinery in agent.buildingHandler.get_buildings(agent.buildingHandler.building.REFINERY):
         if refinery.is_completed and util.squared_distance(self.position, refinery.position) < 3:
             return True
     return False
示例#8
0
 def compare(worker):
     """ sort first based on assignment then based on distance to position """
     return (int(worker.assignment), util.squared_distance(position, worker.position))
示例#9
0
文件: KMeans.py 项目: adsar/repo01
 def classify(self, item):
     """takes as input one single point (item) and computes the distances to the 
     item from each of the k means (cluster centers), then chooses the min() to 
     return the index of the cluster closest to the item (point)"""
     return min(range(self.k),
                key=lambda i: ut.squared_distance(item, self.means[i]))