本文整理汇总了Python中rg.locs_around函数的典型用法代码示例。如果您正苦于以下问题:Python locs_around函数的具体用法?Python locs_around怎么用?Python locs_around使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了locs_around函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _analyze_explosions
def _analyze_explosions(self):
turn = self.current_turn
old_enemiesl = {x.location: x for x in self.enemies(turn-1)}
# Players to examine are non-exploding ones.
old_players = [y for y in self.players(turn-1) if
y.location not in self.turns[turn-1].explode_locs]
new_players_id = {y.robot_id: y for y in self.players(turn)}
# Find players hit with abnormal damage, or 7 w/ guarding
for y in old_players:
num_nearby_enemies = sum (1 for loc in rg.locs_around(y.location)
if loc in old_enemiesl)
max_norm_dmg = 10*num_nearby_enemies
new_hp = (new_players_id[y.robot_id].hp if
y.robot_id in new_players_id else 0)
hp_diff = y.hp - new_hp
guarded = y.location in self.turns[turn-1].guard_locs
if ((hp_diff == 7 and guarded) or hp_diff > max_norm_dmg):
print "{0} hit with {1} damage.".format(y, hp_diff)
# find culprit(s)
candidates = [old_enemiesl[loc] for loc in
rg.locs_around(y.location)
if loc in old_enemiesl]
if len(candidates) == 1:
self._record_explosion_point(candidates[0])
elif len(candidates) > 1:
for e in candidates:
l = e.location
if self.exploded in self.reconstructed_info[l].actions:
self._record_explosion_point(old_enemiesl[l])
开发者ID:rui-lin,项目名称:robot-game,代码行数:31,代码来源:alpha.py
示例2: getNearbyOpenLocations
def getNearbyOpenLocations(self, loc):
locs = set(rg.locs_around(loc, filter_out=('invalid', 'obstacle', 'spawn')))
locs = locs - self.blocked_move_locs
if len(locs) == 0:
locs = set(rg.locs_around(loc, filter_out=('invalid', 'obstacle')))
locs = locs - self.blocked_move_locs
return list(locs)
开发者ID:panzoid,项目名称:robotgame,代码行数:7,代码来源:panzoid_1.py
示例3: act
def act(self, game):
global runda_numer, wybrane_pola
if game.turn != runda_numer:
runda_numer = game.turn
wybrane_pola = set()
# jeżeli się ruszamy, zapisujemy docelowe pole
def ruszaj(loc):
wybrane_pola.add(loc)
return ['move', loc]
# jeżeli stoimy, zapisujemy zajmowane miejsce
def stoj(act, loc=None):
wybrane_pola.add(self.location)
return [act, loc]
# wyznaczamy zbiory różnych pól na planszy
wszystkie = {(x, y) for x in xrange(19) for y in xrange(19)}
wejscia = {loc for loc in wszystkie if 'spawn' in rg.loc_types(loc)}
zablokowane = {loc for loc in wszystkie if 'obstacle' in rg.loc_types(loc)}
druzyna = {loc for loc in game.robots if game.robots[loc].player_id == self.player_id}
wrogowie = set(game.robots) - druzyna
sasiednie = set(rg.locs_around(self.location)) - zablokowane
sasiednie_wrogowie = sasiednie & wrogowie
sasiednie_wrogowie2 = {loc for loc in sasiednie if (set(rg.locs_around(loc)) & wrogowie)} - druzyna
# bezpieczne = sasiednie - sasiednie_wrogowie - sasiednie_wrogowie2 - wejscia - druzyna
bezpieczne = sasiednie - sasiednie_wrogowie - sasiednie_wrogowie2 - \
wejscia - druzyna - wybrane_pola
def mindist(bots, loc):
return min(bots, key=lambda x: rg.dist(x, loc))
def minhp(bots):
return min(bots, key=lambda x: game.robots[x].hp)
if wrogowie:
najblizszy_wrog = mindist(wrogowie,self.location)
else:
najblizszy_wrog = rg.CENTER_POINT
ruch = ['guard']
if self.location in wejscia:
if bezpieczne:
ruch = ['move', mindist(bezpieczne, rg.CENTER_POINT)]
elif sasiednie_wrogowie:
if 9*len(sasiednie_wrogowie) < self.hp:
ruch = stoj('attack',minhp(sasiednie_wrogowie.pop()))
elif bezpieczne:
ruch = ruszaj(mindist(bezpieczne, rg.CENTER_POINT))
else:
ruch = stoj('suicide')
elif sasiednie_wrogowie2 and self.location not in wybrane_pola:
ruch = ['attack', sasiednie_wrogowie2.pop()]
elif bezpieczne:
ruch = ruszaj(mindist(bezpieczne, najblizszy_wrog))
return ruch
开发者ID:astefaniuk,项目名称:linetc,代码行数:60,代码来源:robot24.py
示例4: act
def act(self, game):
# We don't want to die during spawn turns so we move to an empty
# non-spawn position
if game.turn % rg.settings.spawn_every == 0 and "spawn" in rg.loc_types(self.location):
empty_pos = rg.locs_around(self.location, filter_out=("invalid", "obstacle", "spawn"))
if empty_pos:
return ["move", empty_pos[0]]
else:
return ["suicide"]
# Move to one of the "quarters"
around = rg.locs_around(self.location, filter_out=("obstacle", "invalid"))
position = rg.toward(self.location, random.choice(self.DIRECTION))
position = self.closest(around, position)
action = "move"
if self.is_surrounded(game):
return ["suicide"]
# By the end we guard if we have low hp
if 0 < self.hp < 15 and (rg.settings.max_turns - game.turn) < 5:
return ["guard"]
# Attack the weakest opponent around if any
weakest = self.weakest_opponent(game)
if weakest:
# We go KABOOOOOM if we're low on hp!!
if self.hp < 10:
return ["suicide"]
return ["attack", weakest.location]
return [action, position]
开发者ID:bertrandvidal,项目名称:robot_game,代码行数:27,代码来源:swarmer.py
示例5: act
def act(self, game):
# zbiory pól na planszy
# wszystkie pola
wszystkie = {(x, y) for x in xrange(19) for y in xrange(19)}
# punkty wejścia (spawn)
wejscia = {loc for loc in wszystkie if 'spawn' in rg.loc_types(loc)}
# pola zablokowane (obstacle)
zablokowane = {loc for loc in wszystkie if 'obstacle' in rg.loc_types(loc)}
# pola zajęte przez nasze roboty
druzyna = {loc for loc in game.robots if game.robots[loc].player_id == self.player_id}
# pola zajęte przez wrogów
wrogowie = set(game.robots) - druzyna
sasiednie = set(rg.locs_around(self.location)) - zablokowane
sasiednie_wrogowie = sasiednie & wrogowie
sasiednie_wrogowie2 = {loc for loc in sasiednie if (set(rg.locs_around(loc)) & wrogowie)} - druzyna
bezpieczne = sasiednie - sasiednie_wrogowie - sasiednie_wrogowie2 - wejscia - druzyna
print wejscia
# domyślne działanie robota: ruch do środka
ruch = ['move', rg.toward(self.location, rg.CENTER_POINT)]
return ruch
开发者ID:astefaniuk,项目名称:linetc,代码行数:30,代码来源:zbiory.py
示例6: _get_danger
def _get_danger(self, game, loc):
"""Returns the danger of the given location as an integer between
1 and 10.
"""
baseline = 5
if 'spawn' in rg.loc_types(loc):
baseline += 2
enemy_bots = self._get_enemies(game, loc)
for enemy_loc, bot in enemy_bots:
if enemy_loc in rg.locs_around(loc):
baseline = 10 # Can't go here
for adj in rg.locs_around(loc):
if adj in rg.locs_around(enemy_loc):
baseline += (bot.hp - self.hp) // 10
friends = self._get_friends(game, loc)
for friend_loc, bot in friends:
if friend_loc in rg.locs_around(loc):
baseline = 10 # Can't go here
if baseline < 1:
baseline = 1
elif baseline > 10:
baseline = 10
return baseline
开发者ID:scott-w,项目名称:dojo,代码行数:28,代码来源:threat_grid.py
示例7: act
def act(self, game):
# wyznaczamy zbiory różnych pól na planszy
wszystkie = {(x, y) for x in xrange(19) for y in xrange(19)}
wejscia = {loc for loc in wszystkie if 'spawn' in rg.loc_types(loc)}
zablokowane = {loc for loc in wszystkie if 'obstacle' in rg.loc_types(loc)}
druzyna = {loc for loc in game.robots if game.robots[loc].player_id == self.player_id}
wrogowie = set(game.robots) - druzyna
sasiednie = set(rg.locs_around(self.location)) - zablokowane
sasiednie_wrogowie = sasiednie & wrogowie
sasiednie_wrogowie2 = {loc for loc in sasiednie if (set(rg.locs_around(loc)) & wrogowie)} - druzyna
bezpieczne = sasiednie - sasiednie_wrogowie - sasiednie_wrogowie2 - wejscia - druzyna
def mindist(bots, loc):
return min(bots, key=lambda x: rg.dist(x, loc))
ruch = ['guard']
if self.location in wejscia:
if bezpieczne:
ruch = ['move', mindist(bezpieczne, rg.CENTER_POINT)]
if self.location == rg.CENTER_POINT:
ruch = ['guard']
if sasiednie_wrogowie:
if 9*len(sasiednie_wrogowie) < self.hp:
ruch = ['attack', sasiednie_wrogowie.pop()]
if sasiednie_wrogowie2:
ruch = ['attack', sasiednie_wrogowie2.pop()]
return ruch
开发者ID:astefaniuk,项目名称:linetc,代码行数:33,代码来源:robot10.py
示例8: test_locs_around
def test_locs_around(self):
locs = set(rg.locs_around((0,0)))
assert locs == set(((0, 1), (1, 0), (0, -1), (-1, 0)))
locs = set(rg.locs_around((10, 100)))
assert locs == set(((10, 101), (11, 100), (10, 99), (9, 100)))
locs = set(rg.locs_around((0,0), filter_out=["invalid"]))
assert locs == set(((0, 1), (1, 0)))
开发者ID:eminence,项目名称:littlebots,代码行数:9,代码来源:test_rg.py
示例9: places_to_go
def places_to_go(from_loc, occupied_space_list):
ret_list = []
nearby_places = rg.locs_around(from_loc , filter_out=('invalid', 'obstacle'))
if(game['turn']%10 == 0 or game['turn']%10 == 9):
nearby_places = rg.locs_around(from_loc , filter_out=('invalid', 'obstacle', 'spawn'))
for targ in nearby_places:
if not occupied(targ,occupied_space_list):
ret_list.append(targ)
return ret_list
开发者ID:wilkowski,项目名称:GitCode,代码行数:9,代码来源:CarefulBot.py
示例10: open_locs_around
def open_locs_around(self, loc, spawn=True):
locs = []
if spawn:
locs = rg.locs_around(loc, filter_out=('invalid', 'obstacle', 'spawn'))
else:
locs = rg.locs_around(loc, filter_out=('invalid', 'obstacle'))
for i in locs:
if i in self.enemy_bots or i in self.planned_move_locs:
locs.remove(i)
return locs
开发者ID:panzoid,项目名称:robotgame,代码行数:10,代码来源:panzoid_0.py
示例11: panic
def panic(include_suicide):
poss = []
ar = rg.locs_around(curr, filter_out=('invalid','obstacle'))
if include_suicide:
ar = rg.locs_around(curr, filter_out=('invalid','obstacle','spawn'))
for around in ar:
if around not in game_bots:
poss.append(around)
if len(poss) == 0:
return None
return poss[random.randint(0, len(poss) - 1)]
开发者ID:dmhacker,项目名称:rg-bots,代码行数:11,代码来源:Lexicon.py
示例12: isTrapped
def isTrapped(self, loc, with_spawn=False):
trap = True
nearby = []
if with_spawn:
nearby = rg.locs_around(loc, filter_out=('invalid','obstacle','spawn'))
else:
nearby = rg.locs_around(loc, filter_out=('invalid','obstacle'))
for near in nearby:
if near not in self.all_bots:
trap = False
return trap
开发者ID:dmhacker,项目名称:rg-bots,代码行数:11,代码来源:Marquis.py
示例13: guessShot
def guessShot():
for potentialShot in rg.locs_around(self.location, filter_out=('invalid', 'obstacle')):
allyCount = 0
enemyCount = 0
if potentialShot not in game['robots']:
for enemy in rg.locs_around(potentialShot, filter_out=('invalid', 'obstacle')):
if enemy in game['robots']:
if game['robots'][enemy].player_id != self.player_id:
enemyCount += 1
if enemyCount > 0:
return ['attack', potentialShot]
return ['attack', rg.toward(self.location, closestEnemy)]
开发者ID:valdelmeglio,项目名称:valbot,代码行数:12,代码来源:blowcake.py
示例14: act
def act(self, game):
global runda_numer, wybrane_ruchy
if game.turn != runda_numer:
runda_numer = game.turn
wybrane_ruchy = set()
def ruszaj(loc):
wybrane_ruchy.add(loc)
return ['move', loc]
def stoj(act, loc=None):
wybrane_ruchy.add(self.location)
return [act, loc]
wszystkie = {(x, y) for x in xrange(19) for y in xrange(19)}
wejscia = {loc for loc in wszystkie if 'spawn' in rg.loc_types(loc)}
zablokowane = {loc for loc in wszystkie if 'obstacle' in rg.loc_types(loc)}
druzyna = {loc for loc in game.robots if game.robots[loc].player_id == self.player_id}
wrogowie = set(game.robots)-druzyna
sasiednie = set(rg.locs_around(self.location)) - zablokowane
sasiednie_wrogowie = sasiednie & wrogowie
sasiednie_wrogowie2 = {loc for loc in sasiednie if (set(rg.locs_around(loc)) & wrogowie)} - druzyna
bezpieczne = sasiednie - sasiednie_wrogowie - sasiednie_wrogowie2 - wejscia - druzyna - wybrane_ruchy
def mindist(bots, loc):
return min(bots, key=lambda x: rg.dist(x, loc))
if wrogowie:
najblizszy_wrog = mindist(wrogowie,self.location)
else:
najblizszy_wrog = rg.CENTER_POINT
# akcja domyślna, którą nadpiszemy, jak znajdziemy coś lepszego
ruch = ['guard']
if self.location in wejscia:
if bezpieczne:
ruch = ['move', mindist(bezpieczne, rg.CENTER_POINT)]
elif sasiednie_wrogowie:
if 9*len(sasiednie_wrogowie) >= self.hp:
if bezpieczne:
ruch = ['move', mindist(bezpieczne, rg.CENTER_POINT)]
else:
ruch = ['attack', sasiednie_wrogowie.pop()]
elif sasiednie_wrogowie2 and self.location not in wybrane_ruchy:
#ruch = ['attack', sasiednie_wrogowie2.pop()]
if sasiednie_wrogowie:
ruch = stoj('attack',sasiednie_wrogowie.pop())
elif bezpieczne:
#ruch = ['move', mindist(bezpieczne, najblizszy_wrog)]
ruch = ruszaj(mindist(bezpieczne, najblizszy_wrog))
return ruch
开发者ID:astefaniuk,项目名称:linetc,代码行数:53,代码来源:robot_ext.py
示例15: act
def act(self, game):
# wszystkie pola
wszystkie = {(x, y) for x in xrange(19) for y in xrange(19)}
# punkty wejścia
wejscia = {poz for poz in wszystkie if 'spawn' in rg.loc_types(poz)}
# pola zablokowane
zablokowane = {poz for poz in wszystkie if 'obstacle' in rg.loc_types(poz)}
# pola zajęte przez nasze roboty
przyjaciele = {poz for poz in game.robots if game.robots[poz].player_id == self.player_id}
# pola zajęte przez wrogów
wrogowie = set(game.robots) - przyjaciele
# pola sąsiednie
sasiednie = set(rg.locs_around(self.location)) - zablokowane
# pola sąsiednie zajęte przez wrogów
wrogowie_obok = sasiednie & wrogowie
wrogowie_obok2 = {poz for poz in sasiednie if (set(rg.locs_around(poz)) & wrogowie)} - przyjaciele
# pola bezpieczne
bezpieczne = sasiednie - wrogowie_obok - wejscia - przyjaciele
# funkcja znajdująca najsłabszego wroga obok z podanego zbioru (bots)
def minhp(bots):
return min(bots, key=lambda x: game.robots[x].hp)
# działanie domyślne:
ruch = ['move', rg.toward(self.location, rg.CENTER_POINT)]
# jeżeli jesteś w punkcie wejścia, opuść go
if self.location in wejscia:
ruch = ['move', rg.toward(self.location, rg.CENTER_POINT)]
# jeżeli jesteś w środku, broń się
if self.location == rg.CENTER_POINT:
ruch = ['guard']
# jeżeli obok są przeciwnicy, atakuj, o ile to bezpieczne,
# najsłabszego wroga
if wrogowie_obok:
if 9*len(wrogowie_obok) >= self.hp:
if bezpieczne:
ruch = ['move', bezpieczne.pop()]
else:
ruch = ['attack', minhp(wrogowie_obok)]
if wrogowie_obok2:
ruch = ['attack', wrogowie_obok2.pop()]
return ruch
开发者ID:EdwardBetts,项目名称:python101,代码行数:48,代码来源:rgkod10b.py
示例16: nearby_robots
def nearby_robots(self, center, allies=True):
if not center:
return []
locs = rg.locs_around(center)
return [bot for loc, bot in self.g['robots'].items()
if loc in locs and
self.on_team(bot) == allies]
开发者ID:gnmerritt,项目名称:robotgame.org,代码行数:7,代码来源:goose.py
示例17: panic
def panic(self, currLoc):
locs = rg.locs_around(currLoc, filter_out=('invalid','obstacle','spawn'))
target = currLoc
for loc in locs:
if self.isEmptySpace(loc) is True:
target = loc
return target
开发者ID:dmhacker,项目名称:rg-bots,代码行数:7,代码来源:Plat10.py
示例18: coward
def coward(self, game):
# First, make sure you are not in a spawn point
if 'spawn' in rg.loc_types(self.location):
#Move out of spawn point!
return ['move', rg.toward(self.location, rg.CENTER_POINT)]
# second, make sure you are not next to an enemy
locations = rg.locs_around(self.location, filter_out=('invalid', 'obstacle'))
enemies = []
for l in locations:
bot = game['robots'].get(l)
if bot and bot['player_id'] != self.player_id:
enemies.append(bot)
if enemies:
#Find a safe place!
for l in locations:
if not game['robots'].get(l):
# unoccupied spot!
return ['move', l]
else:
# surrounded!
if self.hp < rg.settings.attack_range[1] * len(enemies):
return ['suicide']
else:
target = min(enemies, key=lambda x: x['hp'])
return ['attack', target['location']]
# finally, just chill out.
return ['guard']
开发者ID:Team-Brobot,项目名称:robot-hackathon,代码行数:28,代码来源:bipolar_bot.py
示例19: act
def act(self, game):
# When a new turn is started need to clear the new_locs list.
if self.last_turn != game.turn:
self.new_locs = []
self.last_turn = game.turn
# 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:
self.new_locs.append(self.location)
return ['attack', loc]
random.seed()
# Otherwise move around pick a direction that can randomly
# move to and move there.
moves = rg.locs_around(self.location, filter_out=('invalid', 'obstacle'))
moves = [loc for loc in moves if loc not in self.new_locs]
if len(moves) > 0:
choice = random.choice(moves)
self.new_locs.append(choice)
return ['move', choice]
self.new_locs.append(self.location)
return ['guard']
开发者ID:MoMaT,项目名称:dojo,代码行数:29,代码来源:random_walker_bot_v2.3.1.py
示例20: attack
def attack(self, game, current_return):
if current_return != ['empty']:
return current_return
possible_locations = rg.locs_around(self.location, filter_out = ('invalid', 'obstacle', 'spawn'))
enemy_locs = []
enemy_num = 0
for locs in possible_locations:
if locs in game.robots and game.robots[locs].player_id != self.player_id:
enemy_num += 1
enemy_locs.append(locs)
#Once we have a list of enemies, we can follow a process to determine how to deal with them.
""" if 1 enemy:
if myhealth > enemyhealth:
attack
if myhealth < enemyhealth:
if they have less than 15, suicide
else back away
if 2 or more enemy:
if both less than 15 and mine less than 20, suicide
else back away
else go to move """
for enemy in enemy_locs:
return ['attack', enemy]
#Need to flesh out attack strategy
if enemy_num == 1:
return ['attack', enemy]
return current_return
开发者ID:castlez,项目名称:robogame,代码行数:29,代码来源:pd-strat.py
注:本文中的rg.locs_around函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论