• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python rg.dist函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: act

    def act(self, game):
        # Attack nearby robots. Suicide if we are low on health.
        for loc, bot in game.robots.iteritems():
            if bot.player_id != self.player_id:
                if rg.dist(loc, self.location) <= 1:
                    if self.hp <= 11 and bot.hp <= 15:
                        return ['suicide']
                    else:
                        return ['attack', loc]

        # Find the nearest enemy bot and move towards it if we can. Otherwise head to the center.
        distanceToEnemy = 50
        enemyLocation = rg.CENTER_POINT

        for loc, bot in game.robots.iteritems():
            if bot.player_id != self.player_id:
                distance = rg.dist(loc, self.location)
                if distanceToEnemy > distance:
                    distanceToEnemy = distance
                    enemyLocation = loc

        moveToPoint = rg.toward(self.location, loc)

        if moveToPoint == self.location:
            return ['guard']

        if 'normal' in rg.loc_types(moveToPoint):
            return ['move', moveToPoint]
        else:
            return ['guard']
开发者ID:pneisen,项目名称:robot-game-experiments,代码行数:30,代码来源:scrubby03.py


示例2: act

 def act(self, game):
     
     print
     print "Turn: " +str( game.turn) + "\tBot: " + str(self.robot_id)
     # find closest friend & enemy
     closestFriend = (1000, 1000)
     closestEnemy = (1000, 1000)
     for loc, bot in game.get('robots').items():
         if bot.player_id != self.player_id:
             if rg.wdist(loc, self.location) <= rg.wdist(closestEnemy, self.location):
                 closestEnemy = loc
         else:
             if rg.wdist(loc, self.location) <= rg.wdist(closestFriend, self.location) and self.robot_id != bot.robot_id:
                 closestFriend = loc
     
     for loc, bot in game['robots'].iteritems():
         # if there are enemies around, attack them
         if bot.player_id != self.player_id:
             if rg.dist(loc, self.location) <= 1:
                 return ['attack', loc]
         else:
             # if there are friends around, move to them
             if rg.dist(loc, self.location) > 2:
                 return ['move', rg.toward(self.location, closestFriend)]
                 
     # move towards enemy
     return ['move', rg.toward(self.location, closestEnemy)]
开发者ID:jwygralak67,项目名称:robots,代码行数:27,代码来源:darbot002.py


示例3: act

    def act(self, game):

        # if we're on one of the corners, guard
        if self.location in self.corners:
            return ['guard']

        # if there are enemies around, attack them
        for loc, bot in game.robots.iteritems():
            if bot.player_id != self.player_id:
                if rg.dist(loc, self.location) <= 1:
                    return ['attack', loc]
                #elif rg.dist(loc, self.location) <= 2:
                #    new_loc = rg.toward(self.location,
                #                        loc)
                #    return ['move', new_loc]

        distances = {}
        for corner in self.corners:
            distances[corner] = rg.dist(self.location, corner)

        new_loc = rg.toward(self.location, min(distances, key=distances.get))

        if 'obstacle' in rg.loc_types(new_loc):
            return ['guard']
        else:
            return ['move', new_loc]
开发者ID:jturmel,项目名称:robotgame,代码行数:26,代码来源:triplea.py


示例4: act

 def act(self, game):
     active_team = {}
     active_enemy = {}
     enemy_distance = {}
     active_bots = {}
     for loc, bot in game.get('robots').items():
         if bot.player_id != self.player_id:
             active_enemy[loc] = bot                
             enemy_distance[loc] = 0
         else:
             active_team[loc] = bot
     for loc, bot in game.get('robots').items():
         active_bots[loc] = bot
     for loc in active_enemy:
         for myloc in active_team:
             enemy_distance[loc] = enemy_distance[loc] + rg.dist(loc, myloc)
     if self.hp <= 20:
         return flee(self, active_enemy, active_team, game)
     if 'spawn' in rg.loc_types(self.location):
         if game['turn'] %10 == 0: #spawn about to happen, gtfo
             return ['move', rg.toward(self.location, rg.CENTER_POINT)]
     for loc, bot in game['robots'].iteritems():
         if bot.player_id != self.player_id:
             if rg.dist(loc, self.location) <= 1:
                 print("ATTACK")
                 return ['attack', loc]
             else:                    
                 return['move', rg.toward(self.location, bot.location)]
开发者ID:hayksaakian,项目名称:otherbots,代码行数:28,代码来源:classhamster.py


示例5: act

    def act(self, game):
        # if health < 20, just move to the centre
        if self.hp < 20:
            if self.location == rg.CENTER_POINT:
                return ['guard']
            # if there are enemies around, attack them
            for loc, bot in self.enemy_list(game):
                if rg.dist(loc, self.location) <= 1:
                    return ['attack', loc]
            # move toward the center
            return self.next_move(rg.CENTER_POINT, game)

        # if there are enemies around, attack them
        for loc, bot in self.enemy_list(game):
                if rg.dist(loc, self.location) <= 1:
                    return ['attack', loc]

        #else, move towards weakest enemy
        target_bot = self.find_weakest_bot(self.friendly_list(game),game)
        destination = target_bot.location
        move = self.next_move(destination, game)

        if move is None:
            return ['guard']
        return ['move', move]
开发者ID:jav,项目名称:robotgameplayers,代码行数:25,代码来源:robot006.py


示例6: act

	def act(self, game):
		x,y = self.location
		bot = None
		active_team = {}
		active_enemy = {}
		enemy_distance  = {}
		for loc, bot in game.get('robots').items():
			if bot.get('player_id') != self.player_id:
				active_enemy[loc] = bot
				enemy_distance[loc] = 0
			else:
				active_team[loc] = bot
		for loc in active_enemy:
			for myloc in active_team:
				enemy_distance[loc] = enemy_distance[loc] + rg.dist(loc, myloc)
		prio_loc, attack_loc = self.findPriority(active_team, active_enemy,enemy_distance)
		distance_to_prio = rg.dist(self.location,prio_loc)
		distance_to_attack = BIG_DIST
		if attack_loc:
			distance_to_attack = rg.dist(self.location,attack_loc)
			if distance_to_attack<=1:
				return ['attack', attack_loc]
			else:
				return ['move', rg.toward(self.location, prio_loc)]
		else:
			if prio_loc == self.location:
				if self.hp < SELF_CRITICAL:
					return ['suicide']
				return ['guard']
			return ['move',rg.toward(self.location,prio_loc)]
		return ['guard']
开发者ID:Sebsebeleb,项目名称:TapionRobotGame,代码行数:31,代码来源:Tapion_Body.py


示例7: score_orientation

        def score_orientation(loc):
            self.orientation_score = 0

            #Terrain types
            self._loc_type = rg.loc_types(loc)
            if 'spawn' in self._loc_type:
                self.orientation_score += spawn
                if 'spawn' in rg.loc_types(base_bot):
                    self.orientation_score += spawn_move

            # Distance to center
            self.dist_to_center = round(rg.dist(loc, gravity_center))
            if self.dist_to_center <= inner_circle:
                self.dist_to_center = 0
            self.orientation_score += - self.dist_to_center

            #Distance to friends
            self.dist_to_closest_friend = 0
            for loc2 in friends:
                self._ref_dist = 16
                self.dist_to_closest_friend = 16
                self.dist_to_closest_friend = rg.dist(loc, loc2)
                if self.dist_to_closest_friend < self._ref_dist:
                    self._ref_dist = self.dist_to_closest_friend
            self.orientation_score += round(self.dist_to_closest_friend)
            return self.orientation_score
开发者ID:Lacra17,项目名称:robotgame-bots,代码行数:26,代码来源:chasintheTrane.py


示例8: act

    def act(self, game):
        # if health < 40, just move to the centre
        if self.hp < 40:
            if self.location == rg.CENTER_POINT:
                return ['guard']
            # if there are enemies around, attack them
            for loc, bot in game.robots.iteritems():
                if bot.player_id != self.player_id:
                    if rg.dist(loc, self.location) <= 1:
                        return ['attack', loc]
            # move toward the center
            return ['move', rg.toward(self.location, rg.CENTER_POINT)]

        # if there are enemies around, attack them
        for loc, bot in game.robots.iteritems():
            if bot.player_id != self.player_id:
                if rg.dist(loc, self.location) <= 1:
                    return ['attack', loc]

        #else, move towards weakest enemy
        enemy = self.find_weakest_enemy(game)

        destination = enemy.location
        move = self.next_move(destination, game)
        if move is None:
            return ['guard']
        return ['move', move]
开发者ID:jav,项目名称:robotgameplayers,代码行数:27,代码来源:robot004.py


示例9: act

    def act(self, game):
        enemies = []
        friends = []
        for loc, bot in game.robots.iteritems():
            if bot.player_id != self.player_id:
                enemies.append(bot)
            else:
                friends.append(bot)

        enemies_distances = dict()
        for enemy in enemies:
            enemies_distances[enemy.location] = [0, enemy]
            for friend in friends:
                enemies_distances[enemy.location][0] += rg.dist(friend.location, enemy.location)

        closest_enemies = sorted(enemies_distances.items(), key=lambda x: x[1][0])
        closest_enemies = closest_enemies[:len(closest_enemies)/2]

        # if there are enemies around, attack them
        for loc, bot in game.robots.iteritems():
            if bot.player_id != self.player_id:
                if rg.dist(loc, self.location) <= 1:
                    return ['attack', loc]

        loc, (distance, closest_enemy) = closest_enemies[0]
        closest_enemy = closest_enemies[0][1][1]
        for loc, (distance, enemy) in closest_enemies:
            if rg.dist(enemy.location, self.location) < rg.dist(closest_enemy.location, self.location):
                closest_enemy = enemy

        return ['move', rg.toward(self.location, closest_enemy.location)]
开发者ID:hjwp,项目名称:ldnpydojorobots,代码行数:31,代码来源:team_one_for_the_win.py


示例10: closestSpawnpoint

 def closestSpawnpoint(self, loc, radius=rg.settings.board_size):
     spawn = None
     initial = radius
     for s in rg.settings.spawn_coords:
         if rg.dist(loc, s) <= initial:
             spawn = s
             initial = rg.dist(loc, s)
     return spawn
开发者ID:dmhacker,项目名称:rg-bots,代码行数:8,代码来源:Marquis.py


示例11: act

    def act(self, game):
        if "spawn" in rg.loc_types(self.location):
            s = sanitize(['move', rg.toward(self.location, rg.CENTER_POINT)])
            return s

        adjacent_enemies = []
        for loc, bot in game.get('robots').items():
            if bot.get('player_id') != self.player_id:
                if rg.dist(loc, self.location) <= 1:
                    allies = 0
                    #Find out how many allies are around this enemy
                    for nloc, nbot in game.get('robots').items():
                        if bot.get("player_id") == self.player_id and rg.dist(loc, nloc) <=1:
                            allies = allies + 1
                    adjacent_enemies.append([loc, bot, allies])
            else:
                if "spawn" in rg.loc_types(bot.get("location")): #The friendly wants to get out of spawn, make way for it
                    r = Robot.move(self, game)
                    if r and rg.toward(bot.get("location"), rg.CENTER_POINT) == r[1]:
                            return sanitize(['move', rg.toward(self.location, rg.CENTER_POINT)])
        if adjacent_enemies and self.hp >= CRITICAL_HP:
            if len(adjacent_enemies) * ATTACK_DAMAGE > self.hp: # They can kill me! lets flee!
                return sanitize(self.flee(game))
            adjacent_enemies.sort(key= lambda x: (x[2], x[1].get("hp")))
            return sanitize(['attack', adjacent_enemies[0][0]])
        elif adjacent_enemies and self.hp < CRITICAL_HP:
            return sanitize(self.flee(game))
        else:
            r = Robot.move(self, game)

            if not r:
                return ["guard"]
            
            #Check if allied damaged bots will move to our destination, and if so, let them
            move = True
            for loc, bot in game.get('robots').items():
                if bot.get("player_id") == self.player_id and not bot.location == self.location:
                    if rg.dist(loc, r[1]) <= 1:
                        if Robot.get_destination(bot, game) == r[1]: #our destination matches, let them come
                            if bot.get("hp") < CRITICAL_HP:
                                return ["guard"]
                            else: # Figure out who should be given highest movement priority (based on which one is furthest from middle, or who has lowest hp in tiebreaker)
                                prio = rg.dist(self.location, rg.CENTER_POINT)
                                prio_o = rg.dist(bot.location, rg.CENTER_POINT)

                                if prio == prio_o: #Tie
                                    if self.hp >= bot.hp:
                                        move = True
                                    else:
                                        move = False
                                elif prio > prio_o:
                                    move = True
                                else:
                                    move = False
            if not move:
                return ["guard"]
            else:
                return sanitize(r) or ["guard"]
开发者ID:Lacra17,项目名称:robotgame-bots,代码行数:58,代码来源:Sunguard.py


示例12: act

 def act(self, game):
     available = rg.locs_around(self.location, filter_out = ('invalid', 'obstacle'))
     for loc, bot in game.robots.iteritems():
         if bot.player_id != self.player:
             if rg.dist(loc, self.location) == 1:
                 return ['attack', loc]
             elif rg.dist(loc, self.location) <= 3:
                 return ['move', rg.toward(self.location, loc)]
             else:
                 return ['move', rg.toward(self.location, rg.CENTER_POINT)]
开发者ID:FrankSalad,项目名称:tdcreates,代码行数:10,代码来源:johno_testbot.py


示例13: run_if_scared_and_safe

def run_if_scared_and_safe(this_robot, game, illegals): 
    if not scared(this_robot, game):
        return 'no_action'
    best_distance = 1000
    move = 'no_action'
    for loc in rg.locs_around(this_robot.location, filter_out=('obstacle', 'invalid', 'spawn')):
        if ((not loc in illegals) and safe(this_robot, loc, game) == 1):
            if rg.dist(loc, rg.CENTER_POINT) < best_distance:
                best_distance = rg.dist(loc, rg.CENTER_POINT)
                move = ['move', loc]
    return move
开发者ID:Lacra17,项目名称:robotgame-bots,代码行数:11,代码来源:Dulladob01.py


示例14: act

    def act(self, game):
        
        myId = self.robot_id
        myAge = 0

        if myId in self.age:
            self.age[myId] += 1
            myAge = self.age[myId]
        else:
            self.age[myId] = 0
       
        # get off the spawn point fast
        if myAge <= 3:
            return ['move', rg.toward(self.location, rg.CENTER_POINT)]
        
        # if there are enemies around, attack them
        for loc, bot in game.robots.iteritems():
            if bot.player_id != self.player_id:
                if rg.dist(loc, self.location) <= 1:
                    return ['attack', loc]

                # if we're in the center, stay put
        if self.location == rg.CENTER_POINT:
            return ['guard']

        # move toward the center slowly
        if game.turn % 2:
            return ['move', rg.toward(self.location, rg.CENTER_POINT)]
        
        return['guard']
开发者ID:jwygralak67,项目名称:robots,代码行数:30,代码来源:darbot001.py


示例15: giveOrder

 def giveOrder(self, my_bot):
     # Surround the enemy, if the bot is already next to the enemy then decide to attack or guard or suicide if the bot is surrounded.
     shortest = None
     
     #if my_bot.hp <= rg.settings.attack_range[1]:
     #    return self.panic(my_bot)
     
     for enemy_loc, enemy_bot in self.enemy_bots.iteritems():
         dist = rg.dist(my_bot.location, enemy_loc)
             
         # Found enemy adjacent to bot, attack it or guard
         if dist <= 1:
             return self.guardOrAttack(my_bot, enemy_bot)
         # Found enemy two spaces away, attack open spot in between in case it moves there.
         #elif dist <= 2 and random.randint(0,1) == 1:
         #    return self.preemptiveAttack(my_bot, enemy_bot)
         # Find the enemy closest to bot, ignoring any enemies that are already surrounded
         if len(self.open_locs_around(enemy_loc)) > 0:
             if shortest == None or dist < shortest[0]:
                 shortest = (dist, enemy_loc)
                 
     # Bot is not directly next to enemy, try to move to a spot adjacent to the closest enemy. 
     if shortest != None:     
         return self.moveTowards(my_bot, shortest[1])
     # All enemy bots are surrounded, just default this bot to move towards center or guard if already at center.
     else:
         return self.moveTowards(my_bot, rg.CENTER_POINT)
开发者ID:panzoid,项目名称:robotgame,代码行数:27,代码来源:panzoid_0.py


示例16: testact

    def testact(self, game, meta=2):
        # self.__init__() #Calling __init__ because of LIES
        target = rg.CENTER_POINT

        if self.location == target:
            return self.guard()

        for loc, bot in game.get('robots').items():
            if bot.player_id != self.player_id:
                if rg.dist(loc, self.location) <= 1:
                    return self.attack(loc)

        t0 = time()
        path = astar_find_path(self.location, target)
        t = time()
        print("A Star Pathfinding took "+str((t-t0)*1000)+" milliseconds. "+str(len(path))+" steps.")

        next_step = path[1]
        
        # t0 = time()
        # path = self.nice_find_path(self.location, target, game)
        # t = time()
        # print("Best-First Pathfinding took "+str((t-t0)*1000)+" milliseconds. "+str(len(path))+" steps.")

        if len(path) > 1:

            print(next_step)
            print("#############      awesome, we got a path      ###########")
            return self.move(next_step)

        print("CRAP: No path found from "+str(self.location))
        return self.guard()
开发者ID:hayksaakian,项目名称:robotgamebot,代码行数:32,代码来源:kamikaze.py


示例17: act

      def act(self, game):

                  minDist = 1000000
                  minDistLoc = self.location
                  for loc, bot in game['robots'].iteritems():                                
                                if bot.player_id != self.player_id:
                                                  if rg.dist(loc, self.location) <= 1:
                                                                        return ['attack', loc]


                                elif rg.dist(loc,self.location) < minDist:
                                        minDist = rg.dist(loc,self.location)
                                        minDistLoc = loc

                  
                  return ['move',rg.toward(self.location,loc)]
开发者ID:goncalopereira,项目名称:robotgame,代码行数:16,代码来源:robotp_1.py


示例18: act

    def act(self, game):
        ennemies_around = []
        toward_center_location = rg.toward(self.location, rg.CENTER_POINT)
        
        for location, bot in game.robots.iteritems():
            if bot.player_id != self.player_id:
                if rg.dist(location, self.location) <= 1:
                    ennemies_around.append(location)

            if location == toward_center_location:
                if bot.player_id == self.player_id:
                    return ['guard']
                    

        if len(ennemies_around) > 2:
            return ['suicide']
        if len(ennemies_around) > 0:
            return ['attack', ennemies_around[0]]

        for location, bot in game.robots.iteritems():
            if bot.player_id == self.player_id:
                if self.give_way(location, toward_center_location):
                    print location, toward_center_location, self.location
                    return ['guard']

        return ['move', rg.toward(self.location, rg.CENTER_POINT)]
开发者ID:hjwp,项目名称:ldnpydojorobots,代码行数:26,代码来源:t4_is_cross.py


示例19: strong_hunt_the_weak

def strong_hunt_the_weak(this_robot, game, illegals):
    if(this_robot.hp < 30): return 'no_action'
    weakest_enemy = 20
    best_move = 'no_action'
    for bot in one_robots:
        if bot.player_id != this_robot.player_id:
            if bot.hp < weakest_enemy:
                weakest_enemy = bot.hp
                if bot.hp <= 5 and (not bot.location in illegals) and (not surrounders(this_robot, game, bot.location) > 1):
                    best_move = ['move', bot.location]
                    weakest_enemy = bot.hp
                elif not this_robot.location in illegals:
                    best_move = ['attack', bot.location]
                    weakest_enemy = bot.hp
    for bot in two_robots:
        if bot.player_id != this_robot.player_id:
            if bot.hp < weakest_enemy:
                targetx = towardsx_if_not_spawn(this_robot.location, bot.location)
                targety = towardsy_if_not_spawn(this_robot.location, bot.location)
                if not (targetx == 'no_move'):
                    if not (targetx in illegals or surrounders(this_robot, game, targetx) > 1):
                        best_move = ['move', targetx]
                        weakest_enemy = bot.hp
                if not (targety == 'no_move'):
                    if not (targety in illegals or surrounders(this_robot, game, targety) > 1):
                        if targetx == 'no_move' or rg.dist(targetx, rg.CENTER_POINT) > rg.dist(targety, rg.CENTER_POINT):
                        	best_move = ['move', targety]
                        	weakest_enemy = bot.hp
    return best_move
开发者ID:Lacra17,项目名称:robotgame-bots,代码行数:29,代码来源:Dulladob01.py


示例20: nearestMember

 def nearestMember(self, location):
     selected = {}
     dist = 100
     for bot in self.bots:
         if rg.dist(bot.location, location) < dist:
             selected = bot
     return selected
开发者ID:dmhacker,项目名称:rg-bots,代码行数:7,代码来源:Plat10.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python rg.loc_types函数代码示例发布时间:2022-05-26
下一篇:
Python rconsole.spawn_server函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap