当前位置: 首页>>代码示例>>Python>>正文


Python utils.distance函数代码示例

本文整理汇总了Python中utils.distance函数的典型用法代码示例。如果您正苦于以下问题:Python distance函数的具体用法?Python distance怎么用?Python distance使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了distance函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: next_step

    def next_step(self, things):
        '''Zombies attack if in range, else move in direction of players.'''
        action = None

        # possible targets for movement and attack
        humans = [thing for thing in things.values()
                  if isinstance(thing, Player)]
        positions = possible_moves(self.position, things)

        if humans:
            # targets available
            target = closest(self, humans)

            if distance(self.position, target.position) < self.weapon.max_range:
                # target in range, attack
                action = 'attack', target
            else:
                # target not in range, _try_ to move
                if positions:
                    by_distance = lambda position: distance(target.position,
                                                            position)
                    best_position = sorted(positions, key=by_distance)[0]
                    action = 'move', best_position
        else:
            # no targets, just wander around
            if positions:
                action = 'move', random.choice(positions)

        return action
开发者ID:MaicoLeberle,项目名称:zombsole,代码行数:29,代码来源:things.py

示例2: connect

def connect( self, pos ):
    """Search for any user-drawn platforms near pos. If one is found see if pos is
    close to either of its endpoints. If it is near an endpoint, set pos to that endpoint."""
    MAX_DIST = 30
    shape    = self.physics_interface.space.nearest_point_query_nearest( Vec2d( *pos ), 
                                                                         MAX_DIST, 
                                                                         COLLTYPE_USERPLAT | COLLTYPE_LAVA | COLLTYPE_USERCURVE )

    if shape:

        # Make sure magnets only connect two endpoints from different lines.
        touching_line = self.physics_interface.smap[ shape ]
        if touching_line != self.target_line and \
           ( shape.collision_type == COLLTYPE_USERPLAT or shape.collision_type == COLLTYPE_LAVA or shape.collision_type == COLLTYPE_USERCURVE ):

            if shape.collision_type == COLLTYPE_LAVA:
                start = touching_line.points[:2]
                end   = touching_line.points[2:]
            else:
                start = touching_line.get_start()
                end   = touching_line.get_end() 

            if distance( start, pos ) <= MAX_DIST:
                pos = Vec2d( *start )
            elif distance( end, pos ) <= MAX_DIST:
                pos = Vec2d( *end )

    return pos
开发者ID:robbynickles,项目名称:level_build3,代码行数:28,代码来源:magnet.py

示例3: work

    def work(self):
        if not self.config.catch_pokemon:
            return

        if 'catchable_pokemons' in self.cell and len(self.cell['catchable_pokemons']) > 0:
            logger.log('Something rustles nearby!')
            # Sort all by distance from current pos- eventually this should
            # build graph & A* it
            self.cell['catchable_pokemons'].sort(
                key=
                lambda x: distance(self.position[0], self.position[1], x['latitude'], x['longitude']))

            user_web_catchable = 'web/catchable-%s.json' % (self.config.username)
            for pokemon in self.cell['catchable_pokemons']:
                with open(user_web_catchable, 'w') as outfile:
                    json.dump(pokemon, outfile)

            return self.catch_pokemon(self.cell['catchable_pokemons'][0])

        if 'wild_pokemons' in self.cell and len(self.cell['wild_pokemons']) > 0:
            # Sort all by distance from current pos- eventually this should
            # build graph & A* it
            self.cell['wild_pokemons'].sort(
                key=
                lambda x: distance(self.position[0], self.position[1], x['latitude'], x['longitude']))
            return self.catch_pokemon(self.cell['wild_pokemons'][0])
开发者ID:kmcgaire,项目名称:PokemonGoBot,代码行数:26,代码来源:catch_visible_pokemon_worker.py

示例4: _get_nearest_fort_on_lure_way

    def _get_nearest_fort_on_lure_way(self, forts):

        if not self.lure_attraction:
            return None, 0

        lures = filter(lambda x: True if x.get("lure_info", None) != None else False, forts)

        if len(lures):
            dist_lure_me = distance(
                self.bot.position[0], self.bot.position[1], lures[0]["latitude"], lures[0]["longitude"]
            )
        else:
            dist_lure_me = 0

        if dist_lure_me > 0 and dist_lure_me < self.lure_max_distance:

            self.lure_distance = dist_lure_me

            for fort in forts:
                dist_lure_fort = distance(
                    fort["latitude"], fort["longitude"], lures[0]["latitude"], lures[0]["longitude"]
                )
                dist_fort_me = distance(fort["latitude"], fort["longitude"], self.bot.position[0], self.bot.position[1])

                if dist_lure_fort < dist_lure_me and dist_lure_me > dist_fort_me:
                    return fort, dist_lure_me

                if dist_fort_me > dist_lure_me:
                    break

            return lures[0], dist_lure_me

        else:
            return None, 0
开发者ID:CadeBrown,项目名称:PokemonGoBot-Manager,代码行数:34,代码来源:move_to_fort.py

示例5: work

    def work(self):
        if 'catchable_pokemons' in self.bot.cell and len(self.bot.cell['catchable_pokemons']) > 0:
            # Sort all by distance from current pos- eventually this should
            # build graph & A* it
            self.bot.cell['catchable_pokemons'].sort(
                key=
                lambda x: distance(self.bot.position[0], self.bot.position[1], x['latitude'], x['longitude'])
            )

            for pokemon in self.bot.cell['catchable_pokemons']:
                with open(user_web_catchable, 'w') as outfile:
                    json.dump(pokemon, outfile)
                self.emit_event(
                    'catchable_pokemon',
                    level='debug',
                    data={
                        'pokemon_id': pokemon['pokemon_id'],
                        'spawn_point_id': pokemon['spawn_point_id'],
                        'encounter_id': pokemon['encounter_id'],
                        'latitude': pokemon['latitude'],
                        'longitude': pokemon['longitude'],
                        'expiration_timestamp_ms': pokemon['expiration_timestamp_ms'],
                    }
                )

            return self.catch_pokemon(self.bot.cell['catchable_pokemons'].pop(0))

        if 'wild_pokemons' in self.bot.cell and len(self.bot.cell['wild_pokemons']) > 0:
            # Sort all by distance from current pos- eventually this should
            # build graph & A* it
            self.bot.cell['wild_pokemons'].sort(
                key=
                lambda x: distance(self.bot.position[0], self.bot.position[1], x['latitude'], x['longitude']))
            return self.catch_pokemon(self.bot.cell['wild_pokemons'].pop(0))
开发者ID:Keahibono,项目名称:PokemonGo-Bot,代码行数:34,代码来源:catch_visible_pokemon.py

示例6: find_closest

def find_closest(location, centroids):
    """Return the item in CENTROIDS that is closest to LOCATION. If two
    centroids are equally close, return the first one.

    >>> find_closest([3, 4], [[0, 0], [2, 3], [4, 3], [5, 5]])
    [2, 3]
    """
    return [x for x in centroids if distance(location,x) == min([distance(location,y) for y in centroids])][0]
开发者ID:j3nnahuang,项目名称:python,代码行数:8,代码来源:recommend.py

示例7: findClosestAtom

def findClosestAtom( frame, coords ):
    extendedCoords = ( coords[0], coords[1], 0 )
    minDist = distance(  extendedCoords , frame.atoms[0].x0 )
    minName = frame.atoms[0].symbol

    for atom in frame.atoms:
        if distance( extendedCoords, atom.x0 ) < minDist:
            minDist = distance( extendedCoords, atom.x0 ) 
            minName = atom.symbol
    return minName
开发者ID:mateuszlis,项目名称:WroSIM,代码行数:10,代码来源:interpolate.py

示例8: best_parent

def best_parent(step):
    ssga = world.ssga
    [motherId, parentId] = ssga.getParents(world.nam_tsize)
    population = ssga.population()
    mother = population[motherId]
    parent = population[parentId]
    distances = [utils.distance(population[i], mother) for i in range(world.popsize)]
    max_distances = np.array(distances).max()
    distance = utils.distance(parent, mother)
    assert distance == max_distances, "Distance from parent %f is different than maximum %f" % (distance, max_distances)
开发者ID:dmolina,项目名称:pyreal,代码行数:10,代码来源:steps.py

示例9: find_closest

def find_closest(location, centroids):
    """Return the item in CENTROIDS that is closest to LOCATION. If two
    centroids are equally close, return the first one.

    >>> find_closest([3, 4], [[0, 0], [2, 3], [4, 3], [5, 5]])
    [2, 3]
    """
    min_dist = lambda x: distance(location, x)
    min_distance = min_dist(min(centroids, key = min_dist))
    return [x for x in centroids if distance(location, x) == min_distance][0]
开发者ID:imranjami,项目名称:YelpMaps,代码行数:10,代码来源:recommend.py

示例10: find_closest

def find_closest(location, centroids):
    """Return the centroid in centroids that is closest to location. If
    multiple centroids are equally close, return the first one.

    >>> find_closest([3.0, 4.0], [[0.0, 0.0], [2.0, 3.0], [4.0, 3.0], [5.0, 5.0]])
    [2.0, 3.0]
    """
    # BEGIN Question 3
    dist = [distance(location, i) for i in centroids]
    res = [item for item in centroids if distance(location, item) == min(dist)][0]
    return res
开发者ID:JasonVann,项目名称:CS61A,代码行数:11,代码来源:recommend.py

示例11: find_closest

def find_closest(location, centroids):
    """Return the item in CENTROIDS that is closest to LOCATION. If two
    centroids are equally close, return the first one.

    >>> find_closest([3, 4], [[0, 0], [2, 3], [4, 3], [5, 5]])
    [2, 3]
    """
    "*** YOUR CODE HERE ***"
    min_dis=min(distance(location, i) for i in centroids)
    for i in range(len(centroids)):
        if distance(location, centroids[i])==min_dis:
            return centroids[i]
开发者ID:chocoluffy,项目名称:Berkeley-CS61A,代码行数:12,代码来源:recommend.py

示例12: work

    def work(self):
        num_catchable_pokemon = 0
        if 'catchable_pokemons' in self.bot.cell:
            num_catchable_pokemon = len(self.bot.cell['catchable_pokemons'])

        num_wild_pokemon = 0
        if 'wild_pokemons' in self.bot.cell:
            num_wild_pokemon = len(self.bot.cell['wild_pokemons'])

        num_available_pokemon = num_catchable_pokemon + num_wild_pokemon

        if num_catchable_pokemon > 0:
            # Sort all by distance from current pos- eventually this should
            # build graph & A* it
            self.bot.cell['catchable_pokemons'].sort(
                key=
                lambda x: distance(self.bot.position[0], self.bot.position[1], x['latitude'], x['longitude'])
            )
            user_web_catchable = os.path.join(_base_dir, 'web', 'catchable-{}.json'.format(self.bot.config.username))
            for pokemon in self.bot.cell['catchable_pokemons']:
                with open(user_web_catchable, 'w') as outfile:
                    json.dump(pokemon, outfile)
                self.emit_event(
                    'catchable_pokemon',
                    level='debug',
                    data={
                        'pokemon_id': pokemon['pokemon_id'],
                        'spawn_point_id': pokemon['spawn_point_id'],
                        'encounter_id': pokemon['encounter_id'],
                        'latitude': pokemon['latitude'],
                        'longitude': pokemon['longitude'],
                        'expiration_timestamp_ms': pokemon['expiration_timestamp_ms'],
                    }
                )

            self.catch_pokemon(self.bot.cell['catchable_pokemons'].pop(0))
            if num_catchable_pokemon > 1:
                return WorkerResult.RUNNING
            else:
                return WorkerResult.SUCCESS

        if num_available_pokemon > 0:
            # Sort all by distance from current pos- eventually this should
            # build graph & A* it
            self.bot.cell['wild_pokemons'].sort(
                key=
                lambda x: distance(self.bot.position[0], self.bot.position[1], x['latitude'], x['longitude']))
            self.catch_pokemon(self.bot.cell['wild_pokemons'].pop(0))

            if num_catchable_pokemon > 1:
                return WorkerResult.RUNNING
            else:
                return WorkerResult.SUCCESS
开发者ID:Calcyfer,项目名称:PokemonGo-Bot,代码行数:53,代码来源:catch_visible_pokemon.py

示例13: similarity

 def similarity(self, stone):
     """ Computes similarity with another stone """
     dc = distance(self.center, stone.center)
     ds = distance(self.size, stone.size)
     da = abs(self.angle - stone.angle)
     if dc > 20:
         return 0.0
     if ds > 20:
         return 0.0
     if da > 20:
         return 0.0
     return 1.0 - max([dc / 20.0, ds / 20.0, da / 20.0])
开发者ID:fuzzthink,项目名称:riverbed-vision,代码行数:12,代码来源:stone.py

示例14: calcHist

def calcHist(frame, extendedAtomsIter, binSize, boxSize, options):
    bins = [0 for _ in range(int(boxSize / (2 * binSize)))]
    extendedAtoms = [atom for atom in extendedAtomsIter]
    for atom in frame.atoms:
        if atom.symbol == options.name1 or options.name1 == 'all':
            for atomLst in extendedAtoms:
                for atom2 in atomLst:
                    if options.name2 == "all" or options.name2 == atom2.symbol:
                        if distance(atom.x0, atom2.x0) < boxSize / 2 and distance(atom.x0, atom2.x0) != 0:
                            for i in range(len(bins)):
                                if i * binSize > distance(atom.x0, atom2.x0):
                                    bins[i] += 1
    return bins
开发者ID:mateuszlis,项目名称:WroSIM,代码行数:13,代码来源:pyrdf.py

示例15: find_closest

def find_closest(location, centroids):
    """Return the item in CENTROIDS that is closest to LOCATION. If two
    centroids are equally close, return the first one.

    >>> find_closest([3, 4], [[0, 0], [2, 3], [4, 3], [5, 5]])
    [2, 3]
    """
    "*** YOUR CODE HERE ***"
    min_dis = distance(location, centroids[0])
    min_cen = centroids[0]
    for li in centroids:
        if distance(location, li) < min_dis:
            min_cen, min_dis = li, distance(location, li)
    return min_cen
开发者ID:winterfellding,项目名称:cs61a,代码行数:14,代码来源:recommend.py


注:本文中的utils.distance函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。