本文整理汇总了Python中rg.wdist函数的典型用法代码示例。如果您正苦于以下问题:Python wdist函数的具体用法?Python wdist怎么用?Python wdist使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wdist函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: safe
def safe():
around = {}
for loc in rg.locs_around(curr, filter_out=('invalid','obstacle','spawn')):
if loc not in self.movements:
if loc not in game_bots:
danger = (len(nearby(True)) * 5)
+ len(nearby(True, 2))
+ rg.wdist(curr, nearest_spawn())
+ rg.wdist(curr, rg.CENTER_POINT)
if loc in rg.settings.spawn_coords:
danger += 100 * (10 - til_spawn)
if rg.wdist(loc, nearest_spawn()) == 1:
if nearest_spawn() in game_bots:
if game_bots[nearest_spawn()].player_id == self.player_id:
danger += 1000
else:
danger -= 100
if moveable(loc) == False:
danger += 2500
around[loc] = danger
output = sorted(around, key=lambda a : around[a])
if len(output) == 0:
return None
duplicated = {}
supposed_best = output[0]
duplicated[supposed_best] = len(nearby_of_location(supposed_best, False))
for out in around.keys():
if supposed_best != out:
if around[supposed_best] == around[out]:
duplicated[out] = len(nearby_of_location(out, False))
return sorted(duplicated, key=lambda p : duplicated[p])[0] # Move to a less crowded area
开发者ID:dmhacker,项目名称:rg-bots,代码行数:32,代码来源:Lexicon.py
示例2: nearestEnemy
def nearestEnemy(self, game):
currentTarget = rg.CENTER_POINT
for loc, bot in game.get('robots').items():
if bot.player_id != self.player_id:
if (rg.wdist(self.location, loc) <= rg.wdist(self.location, currentTarget)):
currentTarget = loc
return currentTarget
开发者ID:ChrisAnn,项目名称:robotgame,代码行数:7,代码来源:simple.py
示例3: closest_enemy
def closest_enemy(player_id, location, game):
closest_dist = 1000
for loc, bot in game['robots'].iteritems():
if bot.player_id != player_id and rg.wdist(location, loc) < closest_dist:
closest = bot
closest_dist = rg.wdist(location,loc)
return closest
开发者ID:bcspragu,项目名称:Robots,代码行数:7,代码来源:Destructotron.py
示例4: act
def act(self, game):
"""Called in every turn, for every instance of Robot
:param game: a dictionary of all robots on the field mapped {location: robot}
:return: any of the following: ['move', (x, y)]
['attack', (x, y)]
['guard']
['suicide']
"""
# check if any robot is right next to us
for (x, y) in rg.locs_around(self.location):
if (x, y) in game['robots']:
# if it is an enemy attack it, otherwise just guard
if game['robots'][(x, y)].player_id != self.player_id:
return ['attack', (x, y)]
else:
return ['guard']
# move towards the closest enemy robot
min_distance = 200
# for loc, robot in list(game['robots'].items()): # --use this with python3.x
for loc, robot in game['robots'].iteritems(): # --use this with python2.x
if robot.player_id != self.player_id and rg.wdist(self.location, loc) < min_distance:
min_distance, target_loc = rg.wdist(self.location, loc), loc
# check if we can move towards the nearest robot
# or someone else will move to that spot
next_move_loc = rg.toward(self.location, target_loc)
if self.is_loc_available(game, next_move_loc):
return ['move', next_move_loc]
return ['guard']
开发者ID:Throdne,项目名称:RebotGame,代码行数:31,代码来源:demo.py
示例5: GetClosestFriendly
def GetClosestFriendly(self):
for loc, bot in self.game.get('robots').items():
if bot.player_id == self.player_id:
if rg.wdist(loc, self.location) <= rg.wdist(self.location, self.closestFriend):
self.closestFriend = loc
#print "Friend = %d" %self.closestFriend
return self.closestFriend
开发者ID:camwin,项目名称:bots,代码行数:7,代码来源:TurtleBot.py
示例6: find_closest_foe
def find_closest_foe(self):
""""Finds enemy robot closest to location of given robot and returns its location.
Breaks ties by lowest HP. Assumes there are enemies remaining"""
closest_robots = []
if self.total_foes:
closest_robot = self.total_foes[0] # take any robot to start out
for rob in self.total_foes:
current_dist = rg.wdist(self.robot.location, rob.location)
if current_dist < rg.wdist(self.robot.location, closest_robot.location):
closest_robot = rob
# make list of closest robots (may include more than one)
for rob in self.total_foes:
current_dist = rg.wdist(self.robot.location, rob.location)
if current_dist == rg.wdist(self.robot.location, closest_robot.location):
closest_robots.append(rob)
# break ties with lowest HP if more than one closest robot
if len(closest_robots) > 1:
lowest_HP_rob = closest_robots[0]
for rob in closest_robots:
if rob.hp < lowest_HP_rob.hp:
lowest_HP_rob = rob
return lowest_HP_rob.location
else: # only one robot, pick him
return closest_robots[0].location
开发者ID:AlexSincennes,项目名称:robotgame-stance-bot,代码行数:31,代码来源:stance-bot.py
示例7: calculate_proposals_for_loc
def calculate_proposals_for_loc(self,src):
panic=False;aggressive=True if self.robots[src]['hp']>=30 else False;proposals=ProposedMoveCollection();safer_neighbours=self.find_safer_neighbours(src);nearby_enemies=self.find_neighbours(src=src,player_id=self.enemy_id);max_damage_to_me=10*len(nearby_enemies);here_is_suicide=is_spawn(src)and self.is_spawn_imminent();i_will_be_killed=self.robots[src]['hp']<=max_damage_to_me
if nearby_enemies and not safer_neighbours and(i_will_be_killed or here_is_suicide):return proposals.add_move(SCORE['suicide'],'suicide',src)
if is_spawn(src)and self.is_spawn_imminent(within=1):panic=True
if len(nearby_enemies)>=2:panic=True
overwhelmed_enemies=[(x,self.count_neighbours(src=x,player_id=self.enemy_id),self.robots[x]['hp'])for x in nearby_enemies if self.count_neighbours(src=x,player_id=self.player_id)>1]
for e in overwhelmed_enemies:score=SCORE['attack_overwhelmed_enemy']+e[1];proposals.add_move(score,'attack',src,e[0])
for e in nearby_enemies:score=SCORE['attack_normal_enemy']+50-self.robots[e]['hp'];proposals.add_move(score,'attack',src,e)
possibles=self.ring_search(src,inclusive=True);possibles=self.filter_locs(possibles,filter_id=self.enemy_id);src_ally_neighbours=self.count_neighbours(src=src,player_id=self.player_id);src_enemy_neighbours=self.count_neighbours(src=src,player_id=self.enemy_id)
for dst in possibles:
if dst in self.enemy_next_moves:score=SCORE['preemptive_strike']+self.enemy_next_moves[dst];proposals.add_move(score,'attack',src,dst)
base_move_score=0
if dst in self.enemy_next_moves:base_move_score-=20*self.enemy_next_moves[dst]
if aggressive and src in self.ally_assignments:
src_target_distance=rg.wdist(src,self.ally_assignments[src]);dst_target_distance=rg.wdist(dst,self.ally_assignments[src])
if dst in self.best_attack_spots:base_move_score+=SCORE['move_to_best_attack_spot']
base_move_score+=100*(src_target_distance-dst_target_distance)
dst_enemy_neighbours=self.count_neighbours(src=dst,player_id=self.enemy_id)
if src==dst:base_move_score+=10
if is_spawn(src)and self.is_spawn_imminent(within=1):base_move_score+=SCORE['move_to_safer_location']
if is_spawn(dst):base_move_score-=10
if is_spawn(dst)and self.is_spawn_imminent():base_move_score-=SCORE['suicide']
if panic and src!=dst:base_move_score+=SCORE['panic']
if dst_enemy_neighbours<src_enemy_neighbours:base_move_score+=SCORE['move_to_safer_location']+dst_enemy_neighbours-src_enemy_neighbours
action='guard'if dst==src else'move';proposals.add_move(base_move_score,action,src,dst)
return proposals
开发者ID:Lacra17,项目名称:robotgame-bots,代码行数:26,代码来源:Waterlinie24.py
示例8: act
def act(self, game):
if self.robot_id in self.mayday:
del self.mayday[self.robot_id]
if self.hp < 10:
return self.kill_self(game)
enemies = []
friends = []
for robot in game.robots.itervalues():
if hasattr(robot, "robot_id"):
friends.append(robot)
else:
enemies.append(robot)
targets = []
for enemy in enemies:
targets.append((enemy, rg.wdist(self.location, enemy.location)))
target, distance = min(targets, key=lambda (a, b): b)
if distance == 1:
self.mayday[self.robot_id] = target.location
return ["attack", target.location]
if self.mayday:
targets = [(t, rg.wdist(self.location, t)) for t in self.mayday.values()]
target, _ = min(targets, key=lambda (a, b): b)
if rg.wdist(self.location, target) == 1:
return ["attack", target]
return ["move", rg.toward(self.location, target)]
return ["move", rg.toward(self.location, target.location)]
开发者ID:hjwp,项目名称:ldnpydojorobots,代码行数:32,代码来源:arnold.py
示例9: GetClosestEnemy
def GetClosestEnemy(self):
for loc, bot in self.game.get('robots').items():
if bot.player_id != self.player_id:
if rg.wdist(loc, self.location) <= rg.wdist(self.location, self.closestEnemy):
self.closestEnemy = loc
#print "Enemy = %d, %d" %self.closestEnemy
return self.closestEnemy
开发者ID:camwin,项目名称:bots,代码行数:7,代码来源:TurtleBot.py
示例10: 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
示例11: closest_bro
def closest_bro(self,game):
closest_dist = 1000
for loc, bot in game['robots'].iteritems():
if self.location != loc and bot.player_id == self.player_id and rg.wdist(self.location, loc) < closest_dist:
closest = bot
closest_dist = rg.wdist(self.location,loc)
return closest, closest_dist
开发者ID:bcspragu,项目名称:Robots,代码行数:7,代码来源:Destructotron.py
示例12: act
def act(self, game):
num_enemies = self.num_enemies(game)
if num_enemies * 9 > self.hp:
return ['suicide']
min_distance = float("inf")
move_to = rg.CENTER_POINT
for location, bot in game.get('robots').items():
if bot.get('player_id') != self.player_id:
if rg.dist(location, self.location) <= 1:
return ['attack', location]
if bot.get('player_id') == self.player_id:
if rg.wdist(location, self.location) < min_distance:
min_distance = rg.wdist(location, self.location)
move_to = location
if min_distance < 2:
move_to = rg.CENTER_POINT
if self.location == rg.CENTER_POINT:
return ['guard']
if self.num_frieds(game) > 1:
return ['guard']
return ['move', rg.toward(self.location, move_to)]
开发者ID:hayksaakian,项目名称:otherbots,代码行数:25,代码来源:snoflake.py
示例13: TurtleMode
def TurtleMode(self,game):
#for loc,bot in game.robots.items():
# if bot.player_id == self.player_id:
if self.hp <= 15:
if rg.wdist(self.location, GetClosestEnemy(self)) == 1:
if rg.wdist(self.location, GetClosestFriendly(self)) > 1:
print "Bot at %d %d entered turtle mode" %self.location
return True
开发者ID:camwin,项目名称:bots,代码行数:8,代码来源:TurtleBot.py
示例14: hunt
def hunt(self, robot):
if rg.wdist(self.me.location, robot.location) <= 1:
return Move(['attack', robot.location], "Hunter %s" % str(robot.location))
for enemyRobotLocation in _gameView.locationsOfEnemyRobots:
if rg.wdist(self.me.location, enemyRobotLocation) <= 1:
return Move(['attack', enemyRobotLocation], "Hunter [found other enemy] %s" % str(enemyRobotLocation))
walker = Walker(self.me)
return Move(walker.goTowards(robot.location), "Hunter %s [needed to walk]" % str(robot.location))
开发者ID:kamil-nowosad,项目名称:robotgame,代码行数:9,代码来源:robot-v4-hunter-retreater-improved.py
示例15: process_attack_state
def process_attack_state(self, game):
# Try parry from predicted explosion
dangers = {x.location: x for x in self.neighbours_exploding()}
if len(dangers) > 0:
res = self.try_parry(game, spawn_points_ok=True)
return res if res else ['guard']
# Try escape from spawn reset
res = self.escape_spawn_trap_move(game)
if res:
return res
# Combat-mode
targets = self.intel.enemies()
targets = [x for x in targets if
rg.wdist(self.location, x.location) == 1]
targets.sort(lambda x, y: cmp(x.hp, y.hp))
# 1 block away targets (in combat)
if len(targets) > 0:
# try parry if may die or getting double-team'd and can't kill
# opponent
if ((len(targets) == 1 and self.hp <= 10 and targets[0].hp > 9) or
(len(targets) > 1 and any(x for x in targets if x.hp > 15))):
res = self.try_parry(game, spawn_points_ok=False)
if res:
return res
# explode or attack decision
if self.should_explode_over_attack():
return ['suicide']
else:
return ['attack', targets[0].location]
# TODO: team up attacks
# 2 block away targets
targets = self.intel.enemies()
targets = [x for x in targets if
rg.wdist(self.location, x.location) == 2]
targets.sort(lambda x, y: cmp(x.hp, y.hp))
for x in targets:
# Can hit predicted loc 1? (towards center)
predicted_loc = rg.toward(x.location, rg.CENTER_POINT)
if rg.wdist(self.location, predicted_loc) == 1:
return ['attack', predicted_loc]
# Try predicted loc 2 (towards robot)
predicted_loc = self.towards(x.location)[0]
return ['attack', predicted_loc]
# for later, if want to coordinate attacks from afar
# targets.sort(lambda x, y: cmp(rg.wdist(self.location,x.location),
# rg.wdist(self.location,y.location)))
return ['guard']
开发者ID:rui-lin,项目名称:robot-game,代码行数:56,代码来源:alpha.py
示例16: runAwayFrom
def runAwayFrom(self, enemy):
valid_locs = rg.locs_around(self.location, filter_out=('invalid', 'obstacle', 'spawn'))
farthest = self.location
farthest_dist = rg.wdist(farthest, enemy.location)
for loc in valid_locs:
dist = rg.wdist(loc, enemy.location)
if dist > farthest_dist:
farthest = loc
farthest_dist = dist
return farthest
开发者ID:Sunlis,项目名称:robot_game_bots,代码行数:10,代码来源:run_away.py
示例17: findNearestEnemy
def findNearestEnemy(self, game):
enemies = self.getEnemies(game)
closest = enemies[0]
closestDist = rg.wdist(closest.location, self.location)
for enemy in enemies[1:]:
dist = rg.wdist(enemy.location, self.location)
if dist < closestDist:
closest = enemy
closestDist = dist
return closest
开发者ID:Sunlis,项目名称:robot_game_bots,代码行数:10,代码来源:run_away.py
示例18: closest_robot
def closest_robot(location, robot_set, exclude_location):
closest = None
closestDistance = 300
for bot in robot_set:
if rg.wdist(location, bot.location) < closestDistance and ((not exclude_location) or (bot.location != location)):
closest = bot
closestDistance = rg.wdist(location, bot.location)
return closest
开发者ID:nattress,项目名称:Misc,代码行数:10,代码来源:ring_of_death.py
示例19: nearbyEnemies
def nearbyEnemies(self, location, radius=1, borderonly=False):
robots = []
for loc, bot in self.all_bots.iteritems():
if bot.player_id != self.playerid():
if borderonly:
if rg.wdist(loc, location) == radius:
robots.append(bot)
else:
if rg.wdist(loc, location) <= radius:
robots.append(bot)
return robots
开发者ID:dmhacker,项目名称:rg-bots,代码行数:11,代码来源:Plat10.py
示例20: nearbyMembers
def nearbyMembers(self, location, radius = 1, borderonly=False):
robots = []
for bot in self.bots:
if bot.location is not location:
if borderonly:
if rg.wdist(bot.location, location) == radius:
robots.append(bot)
else:
if rg.wdist(bot.location, location) <= radius:
robots.append(bot)
return robots
开发者ID:dmhacker,项目名称:rg-bots,代码行数:11,代码来源:Plat10.py
注:本文中的rg.wdist函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论