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)]
def act(self, game): my_team = self.player_id if 'spawn' in rg.loc_types(self.location): return ['move', rg.toward(self.location, rg.CENTER_POINT)] else: # Get the nearby locations near_locations = rg.locs_around(self.location) # For each location see if there is a robot there or not... for loc in near_locations: try: robot_location = game.robots[loc] # There is... # If it is our own robot, just move to the center one step. Stop moving when we reach the center. if game.robots[loc][ 'player_id'] == my_team and self.location != rg.CENTER_POINT: return [ 'move', rg.toward(self.location, rg.CENTER_POINT) ] elif game.robots[loc]['player_id'] != my_team: return ['attack', loc] except KeyError: # There are no robots there... pass return ['guard']
def act(self, game): # TODO: # Swarm around the sub-leader bot # attack in group, increase radius of search to 2-3 tiles away #print " robot {} has moves ".format(self.robot_id), self.move_randomly(game) #print " robot {} has {} enemy around".format(self.robot_id, len(self.enemy_around(game))) if self.move_randomly(game): return self.move_randomly(game) else: enemies_1 = self.enemy_around(game, 1) enemies_2 = self.enemy_around(game) if len(enemies_1) > 0: if self.hp <= 15: return ['suicide'] #attack the weakest enemy weakest_enemy = self.find_weakest(enemies_1) return ['attack', weakest_enemy.location] elif len(enemies_2) > 0: #no enemy around, extend to 2nd radius weakest_enemy = self.find_weakest(enemies_2) if rg.wdist(self.location, weakest_enemy.location) == 2: return ['attack', rg.toward(self.location, weakest_enemy.location)] else: return ['move', rg.toward(self.location, weakest_enemy.location)] return ['guard'] #else: #next_move = rg.toward(self.location, rg.CENTER_POINT) #if next_move in game.robots #else: # return ['move', next_move] return ['guard']
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']
def act(self, game): my_team = self.player_id if 'spawn' in rg.loc_types(self.location): # Store the position of the spawning point self.spawn_loc = self.location # Just move one place toward the center return ['move', rg.toward(self.location, rg.CENTER_POINT)] else: # Get the nearby locations near_locations = rg.locs_around(self.location) # For each location see if there is a robot there or not... for loc in near_locations: try: robot_location = game.robots[loc] # There is... # TODO AR: there is problem. When robots from our team are near to each other # they start moving to the center. in late phases of game it will be more often. # If it is our own robot, just move to the center one step. If we are more than 1 distance from the spawning location, stop moving. # this is to avoid moving to the center. #if game.robots[loc]['player_id'] == my_team and self.location != rg.CENTER_POINT: if game.robots[loc]['player_id'] == my_team and rg.wdist(self.location,self.spawn_loc) == 1: return ['move', rg.toward(self.location, rg.CENTER_POINT)] # Just to take advantage of the situation, if there is an enemy near, attack it. elif game.robots[loc]['player_id'] != my_team: return ['attack', loc ] except KeyError: # There are no robots there... pass return ['guard']
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)]
def act(self, game): # first run: make the 'updated' attribute if not hasattr(self, 'groups_updated'): self.groups_updated = -1 self.ally_groups = [] self.enemy_groups = [] self.taget_group = None self.target_location = rg.CENTER_POINT self.bfs_grid = [] # 'self' is an entity shared by all bots. each frame, only one bot needs to make decisions, then they are shared if self.groups_updated < game['turn']: self.groups_updated = game['turn'] self.ally_groups, self.enemy_groups = self.compute_groups(game, True) # sort groups by strength (sum of health) self.enemy_groups = sorted(self.enemy_groups, key=(lambda grp: sum([game['robots'][loc].hp for loc in grp]))) # attack weakest group # TODO multiple targets self.target_group = self.enemy_groups[0] target_location_x = sum([loc[0] for loc in self.target_group]) target_location_y = sum([loc[1] for loc in self.target_group]) self.target_location = (target_location_x, target_location_y) self.bfs_grid = bfs_tree(game['robots'], self.target_location, self.player_id) # bot-specifics: move towards target or attack if there next = self.bfs_grid[self.location[0]][self.location[1]] # print self.location, "to", self.target_location, "via", next if next is not None: if next in game['robots']: return self.guard_or_attack(game) else: return ['move', next] elif rg.toward(self.location, self.target_location) in game['robots']: return ['attack', rg.toward(self.location, self.target_location)] else: return self.guard_or_attack(game)
def act(self, game): self.game = game enemy_location = self.closest_adjacent_enemy() if 'spawn' in rg.loc_types(self.location): destinations = rg.locs_around(self.location, filter_out=('invalid','obstacle','spawn')) if destinations: # print("Robot {0}: In a spawn. Moving to {1}".format(str(self.location), str(destination))) return self.move(destinations[0]) else: return self.guard() elif enemy_location: # print("Robot {0}:Trying to attack. Location:{1}".format(str(self.location), str(enemy_location))) return self.attack(enemy_location) else: enemies = [] for loc, robot in game.robots.items(): if robot.player_id != self.player_id: enemies.append(loc) enemies.sort() if rg.toward(self.location, enemies[0]) == self.location: # print("Robot {0}:Don't want to collide; guarding.".format(self.location)) return self.guard() else: destination = rg.toward(self.location, enemies[0]) # print("Robot {0}: Not in position; moving to {1}.".format(self.location, destination)) if 'spawn' not in rg.loc_types(destination): return self.move(rg.toward(self.location, enemies[0])) else: return self.move(rg.toward(self.location, rg.CENTER_POINT))
def act(self, game): wszystkie = {(x, y) for x in xrange(19) for y in xrange(19)} wejscia = {poz for poz in wszystkie if 'spawn' in rg.loc_types(poz)} zablokowane = {poz for poz in wszystkie if 'obstacle' in rg.loc_types(poz)} druzyna = {poz for poz in game.robots if game.robots[poz].player_id == self.player_id} wrogowie = set(game.robots) - druzyna sasiednie = set(rg.locs_around(self.location)) - zablokowane sasiednie_wrogowie = sasiednie & wrogowie sasiednie_wrogowie2 = {poz for poz in sasiednie if (set(rg.locs_around(poz)) & wrogowie)} - druzyna # działanie domyślne: ruch = ['move', rg.toward(self.location, rg.CENTER_POINT)] if self.location in wejscia: ruch = ['move', rg.toward(self.location, rg.CENTER_POINT)] if self.location == rg.CENTER_POINT: ruch = ['guard'] if sasiednie_wrogowie: if 9*len(sasiednie_wrogowie) >= self.hp: pass else: ruch = ['attack', sasiednie_wrogowie.pop()] if sasiednie_wrogowie2: ruch = ['attack', sasiednie_wrogowie2.pop()] return ruch
def act(self, game): if self.hp < 14: return ['suicide'] # Calculate nearby bots nearby_bots = 0 for loc, bot in game.robots.iteritems(): if bot.player_id != self.player_id: if rg.dist(loc, self.location) <= 2: nearby_bots += 1 enemy_loc = loc # Attack or suicide if bots nearby if nearby_bots == 1: if rg.dist(enemy_loc, self.location) == 1: return ['attack', enemy_loc] else: return ['attack', rg.toward(self.location, enemy_loc)] elif nearby_bots > 2: return ['suicide'] # If already at center, guard the center if self.location == rg.CENTER_POINT: return ['guard'] # Move to center next_move_to_center = rg.toward(self.location, rg.CENTER_POINT) #import pdb; pdb.set_trace() if next_move_to_center in game['robots']: return ['guard'] return ['move', next_move_to_center]
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)]
def compute_command(self, turn, bot, enemy_bots): if bot.location in self.SPAWN_LOCATIONS: self.move( turn, bot, choice(bot.movements) if bot.movements else rg.toward( bot.location, rg.CENTER_POINT)) return # if there are enemies around, attack them if bot.enemies: enemies = [enemy_bots[loc] for loc in bot.enemies] weak_enemies = [ b for b in enemies if self.health(b) <= self.MIN_ATTACK_DAMAGE ] if weak_enemies: self.attack(turn, bot, choice(weak_enemies).location) return if self.health(bot) < len(enemies) * self.MIN_ATTACK_DAMAGE: self.suicide(turn, bot) return target = min(enemies, key=self.health) self.attack(turn, bot, target.location) return # if we're in the center, stay put if bot.location == rg.CENTER_POINT: self.guard(turn, bot) return # move toward the center self.move(turn, bot, rg.toward(bot.location, rg.CENTER_POINT))
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)]
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 ruch = ['move', rg.toward(self.location, rg.CENTER_POINT)] if self.location in wejscia: ruch = ['move', rg.toward(self.location, 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
def act(self, game): # Borrowed sets of sets from github.com/ramk13 all_locs = {(x, y) for x in xrange(19) for y in xrange(19)} spawn = {loc for loc in all_locs if 'spawn' in rg.loc_types(loc)} obstacle = {loc for loc in all_locs if 'obstacle' in rg.loc_types(loc)} team = {loc for loc in game.robots if game.robots[loc].player_id == self.player_id} enemy = set(game.robots) - team adjacent = set(rg.locs_around(self.location)) - obstacle adjacent_enemy = adjacent & enemy safe = adjacent - adjacent_enemy - spawn - team north = {loc for loc in team if loc[1] > 9 and loc[0] > 9} east = {loc for loc in team if loc[1] <= 9 < loc[0]} west = {loc for loc in team if loc[1] <= 9 and loc[0] <= 9} south = team - north - east - west x, y = int(sum(x for x, y in north if self)/len(north)), int(sum(y for x, y in north)/len(north)) sx, sy = int(sum(x for x, y in south)/len(south)), int(sum(y for x, y in south)/len(south)) if self.location in ((nx, ny), (sx, sy)) or rg.locs_around(self.location) in ((nx, ny), (sx, sy)): if self.location not in spawn: return ['guard'] if len(adjacent_enemy) >= 3: return ['suicide'] if self.hp < 9 and adjacent_enemy: return ['suicide'] if adjacent_enemy: return ['attack', min(adjacent_enemy, key=lambda x: rg.dist(x, self.location))] if safe: if self.location in north: return ['move', rg.toward(self.location, (nx, ny))] else: return ['move', rg.toward(self.location, (sx, sy))] return ['guard']
def act(self, game): if 'spawn' in rg.loc_types(self.location): return ['move', rg.toward(self.location, rg.CENTER_POINT)] my_friendly_neighbours = self.get_neighbours(game) if my_friendly_neighbours: return ['move', rg.toward(self.location, rg.CENTER_POINT)] bad_neighbours = self.get_neighbours(game, friendly=False, onlyspawn=False) # CAMP THE SPAWN! SHOOT NOW! shoot = 'attack' if bad_neighbours: if random.randint(0, 10) > 7: print('HAHAHA! DIE DIE DIE!') return [shoot, bad_neighbours[0]['location']] friends = [ bot for bot in game.robots.values() if bot['player_id'] == self.player_id ] def check_friend(current_close_friend, new_friend): if not current_close_friend: return new_friend if rg.wdist(self.location, new_friend.location) < rg.wdist( self.location, current_close_friend.location): return new_friend return current_close_friend closest_friend = reduce(check_friend, friends, None) return ['guard']
def act(self, game): def czy_wejscie(poz): if 'spawn' in rg.loc_types(poz): return True return False def czy_wrog(poz): if game.robots.get(poz) != None: if game.robots[poz].player_id != self.player_id: return True return False # lista wrogów obok wrogowie_obok = [] for poz in rg.locs_around(self.location): if czy_wrog(poz): wrogowie_obok.append(poz) # jeżeli jesteś w punkcie wejścia, opuść go if czy_wejscie(self.location): return ['move', rg.toward(self.location, rg.CENTER_POINT)] # jeżeli obok są przeciwnicy, atakuj if len(wrogowie_obok): return ['attack', wrogowie_obok.pop()] # jeżeli jesteś w środku, broń się if self.location == rg.CENTER_POINT: return ['guard'] # idź do środka planszy return ['move', rg.toward(self.location, rg.CENTER_POINT)]
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']
def act(self, game): self.game = game max_angry = 10 angry = 8 is_angry = random.choice([True]*angry+[False]*(max_angry-angry)) local_enemies = self.local_enemies(game) empty_spaces = [e for e in self.local_spaces() if e not in local_enemies.keys()] if local_enemies: if self.hp < 10 and len(local_enemies) > 1: return ['suicide'] if is_angry: return ['attack', random.choice(local_enemies.keys())] if empty_spaces: return ['move', random.choice(empty_spaces)] return['guard'] enemies = self.enemies(game) for enemy in enemies: displacement = (self.location, enemy.location) if rg.wdist(*displacement) == 2: attack_loc = rg.toward(*displacement) if is_angry: return ['move', attack_loc] if self.in_square(attack_loc) != 'friend': return ['attack', attack_loc] return ['move', rg.toward(self.location, random.choice(self.enemies(game)).location)]
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 # 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 if wrogowie_obok: ruch = ['attack', wrogowie_obok.pop()] return ruch
def act(self, game): blob_locs = set(self.location) #if one nearby enemy, attack #if surrounded by enemies, suicide #in between, run towards center. adj_enemies = [] for l in set(rg.locs_around(self.location, ['spawn', 'invalid'])).difference(blob_locs): if l in game.get('robots').keys(): if game['robots'][l].get('player_id') != self.player_id: adj_enemies.append(game['robots'][l]) if len(adj_enemies) >= 4: return ['suicide'] elif len(adj_enemies) > 1: #if in center, stand and fight lowest hp enemy if self.location == rg.CENTER_POINT: target = min(adj_enemies, key=lambda k: k['hp']) return['attack', target['location']] else: return ['move', rg.toward(self.location, rg.CENTER_POINT)] elif len(adj_enemies) == 1: return ['attack', adj_enemies[0]['location']] #hold the center if self.location == rg.CENTER_POINT: return ['guard'] elif self.in_blob(self.location, blob_locs, game) and rg.CENTER_POINT in blob_locs: return ['guard'] #don't hang around spawn points if 'spawn' in rg.loc_types(self.location): return ['move', rg.toward(self.location, rg.CENTER_POINT)] #if nothing better to do, move toward center. return ['move', rg.toward(self.location, rg.CENTER_POINT)]
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
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"]
def act(self, game): # Update the class variables if this is a new turn. if game.turn != self.currentTurn: # If this is the very first turn, print out some info. if game.turn == 1: print "The rally point is: {0}".format(self.rallyPoint); self.updateVariables(game); self.currentTurn = game.turn; print "New Turn! " + str(self.currentTurn) + " Friends: " + str(self.numberOfFriends) + " Foes: " + str(self.numberOfFoes); # First order of business, if this bot is on a spawn point, we need to get him out of there. if 'spawn' in rg.loc_types(self.location): # Try to move toward the rally point. moveToPoint = rg.toward(self.location, self.rallyPoint); if 'normal' in rg.loc_types(moveToPoint): return ['move', moveToPoint]; else: # Can't move towards the rally point. See where we can move. adjacentLocations = rg.locs_around(self.location); for loc in adjacentLocations: if 'normal' in rg.loc_types(loc): return ['move', loc]; # If we got here, we can't move off the spawn point. Let's try to do some damage if we have a nearby enemy. for loc in adjacentLocations: if loc in game.robots: if game.robots[loc].player_id != self.player_id: return self.attackOrSuicide(loc, game.robots[loc]); # If we are here, nothing else we can do, but guard. We must be blocked by our guys. Hopefully they will get out of the way. return ['guard']; # Now some strategy. if self.numberOfFoes > self.numberOfFriends: # We have less bots than the enemy. Let's play it safe until the numbers are back in our favor. # Head to the rally point if possible. Fight if someone gets in the way, but be passive otherwise. if (self.location == self.rallyPoint): return ['guard']; moveToPoint = rg.toward(self.location, self.rallyPoint); if 'normal' in rg.loc_types(moveToPoint): return ['move', moveToPoint]; else: # We can't move. Attack if we can. for loc in adjacentLocations: if loc in game.robots: if game.robots[loc].player_id != self.player_id: return self.attackOrSuicide(loc, game.robots[loc]); # Guard if we can't move. return ['guard']; else: # We have the numbers advantage. Start hunting. return ['guard'];
def act_kiter(self, game): if 'foe' in map(self.in_square, self.local_spaces()): return self.evade() for square in self.local_spaces(): if self.square_is_threatened(square): return ['attack', rg.toward(self.location, square)] return ['move', rg.toward(self.location, random.choice(self.enemies(game)).location)]
def plan_move(self, game, new_loc): if new_loc == self.location and self.location == rg.CENTER_POINT: return ['guard'] if new_loc == self.location: return ['move', rg.toward(self.location, rg.CENTER_POINT)] around_me = rg.loc_types(new_loc) if around_me == ['normal']: return ['move', rg.toward(self.location, new_loc)] else: return None
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)]
def act(self, game): adjEnemyCount = 0 # adjacent enemy robots # if we're in the center, stay put if self.location == rg.CENTER_POINT: print 'guard!' return ['guard'] # if in a spawn near spawn time, move towards centre if game.turn % 10 >= 8 and "spawn" in rg.loc_types(self.location): print 'Running away from spawn' 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: for dest in rg.locs_around(self.location, filter_out=('invalid', 'obstacle', 'spawn')): print 'diocane' return ['move', dest] ''' assist_action = should_assist(self, game) if (assist_action is not None): return assist_action ''' if not self.is_being_attacked_by_stronger(game): attack_scores = [(self.attack_score(game, friendly_locs, loc), loc) for loc in adjs] maxscore, maxloc = max(attack_scores) if maxscore > 0: print 'attack weaker!' return ["attack", maxloc] else: move_scores = [(self.move_score(game, loc), loc) for loc in adjs] maxscore, maxloc = max(move_scores) guard_score = self.move_score(game, self.location) if maxscore > guard_score: return ["move", maxloc] ''' if bot.player_id != self.player_id: if rg.wdist(loc, self.location) == 1: adjEnemyCount += 1 if adjEnemyCount >= 3: if self.hp <= adjEnemyCount * 9: print 'suicide!' return ['suicide'] if rg.dist(loc, self.location) <= 1: return ['attack', loc] # move toward the center return ['move', rg.toward(self.location, rg.CENTER_POINT)]
def test_toward(self): me = (10,10) dest = (0,0) toward = rg.toward(me, dest) assert toward in [(9,10), (10,9)] dest = (10,12) toward = rg.toward(me, dest) assert toward == (10,11) dest = (10,10) toward = rg.toward(me, dest) assert toward == (10,10)
def act(self, game): # Valid actions valid = [] for loc in rg.locs_around(self.location, filter_out=('invalid', 'obstacle', 'spawn')): valid = valid + [['move', loc]] # move toward the center if ['move', rg.toward(self.location, rg.CENTER_POINT)] in valid: return ['move', rg.toward(self.location, rg.CENTER_POINT)] # Guard return ['guard']
def act(self, game): l = list(rg.locs_around(self.location, filter_out=('invalid', 'obstacle'))) for loc, bot in game.robots.iteritems(): if bot.player_id != self.player_id: if rg.dist(loc, self.location) <= 1: if game.robots[loc].hp <= 10: return ['move', l[0]] if self.hp <=11: for loc, bot in game.robots.iteritems(): if bot.player_id != self.player_id: if rg.dist(loc, self.location) <= 1: return ['suicide'] # if there are enemies around, attack them count = 0 for loc, bot in game.robots.iteritems(): if bot.player_id != self.player_id: if rg.dist(loc, self.location) <= 1: count+=1 if count >=3 and self.hp <=31: return ['suicide'] if count >=2 and self.hp <=21: return ['suicide'] locs = [] count = 0 for loc, bot in game.robots.iteritems(): if bot.player_id != self.player_id: locs.append(loc) for loc, bot in game.robots.iteritems(): if bot.player_id != self.player_id: if rg.dist(loc, self.location) <= 2: if self.flag: if rg.dist(loc, self.location) <= 1: return ['attack', rg.toward(self.location, loc)] self.flag = False return['move', rg.toward(self.location, rg.CENTER_POINT)] self.flag = True return ['attack', rg.toward(self.location, loc)] for loc, bot in game.robots.iteritems(): if bot.player_id == self.player_id: if rg.dist(loc, self.location) <= 3: count+=1 if count >=4: return ['move', rg.toward(self.location, rg.CENTER_POINT)] closest = min(locs) return ['move', rg.toward(self.location, closest)]
def act(self, game): if self.location == rg.CENTER_POINT: return ['guard'] if rg.loc_types(self.location) == 'spawn': 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) <=2: return ['attack', loc] return ['move', rg.toward(self.location, rg.CENTER_POINT)]
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) } 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 # działania domyslne: ruch = ['move', rg.toward(self.location, rg.CENTER_POINT)] # jeżeli jeteś wpkt 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 if wrogowie_obok: if 9 * len(wrogowie_obok) >= self.hp: if bezpieczne: ruch['move', bezpieczne.pop()] else: ruch = ['attack', wrogowie_obok.pop()] if wrogowie_obok2: ruch = ['attack', wrogowie_obok2.pop()] return ruch
def should_attack(robot, game): # if there's an enemy within attacking range, attack neighboring_enemies = get_neighboring_enemies(robot, game) if len(neighboring_enemies) > 0: return random.choice(neighboring_enemies) # if there's an an enemy who can move into attacking range, attack preemptively in case he moves close if ATTACK_PREEMPTIVELY is not False: for loc, other in game['robots'].items(): if rg.wdist(loc, robot.location) == 2: if other.player_id != robot.player_id: if random.random() < ATTACK_PREEMPTIVELY: print "Preemptive attack!", robot.location, loc, rg.toward(robot.location, loc) return rg.toward(robot.location, loc) return None
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
def act(self, game): # if we're in the center, stay put if self.location == rg.CENTER_POINT: return ['guard'] num_enemies_near = sum([ pt in self.enemy_bot_locations(game) for pt in rg.locs_around(self.location)]) if num_enemies_near > 1 and self.hp < 20: return ['suicide'] # if there are enemies around, attack them for loc, bot in game.robots.items(): if bot.player_id != self.player_id: if rg.dist(loc, self.location) <= 1: return ['attack', loc] # move toward the center dist_to_center = rg.wdist(self.location, rg.CENTER_POINT) if dist_to_center > 5: next_location = rg.toward(self.location, rg.CENTER_POINT) else: next_location = self.random_location() if next_location in game.robots: return ['guard'] return ['move', next_location]
def act(self, game): # check if being attacked if self.last_turns_hp < self.hp: self.bait = True last_turns_hp = self.hp # guard if attacked if self.bait: return ['guard'] closest_bot_loc = None closest_bot_distance = 50000 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: return ['suicide'] else: return ['attack', loc] if rg.dist(loc, self.location) < closest_bot_distance: closest_bot_distance = rg.dist(loc, self.location) closest_bot_loc = loc # move towards an enemy if closest_bot_loc: move_loc = rg.toward(self.location, closest_bot_loc) if move_loc not in game['robots']: return ['move', move_loc] return ['guard']
def act(self, game): center = rg.CENTER_POINT enemy_bots = [ b for b in game.robots.values() if b.player_id != self.player_id ] target = min(enemy_bots, key=lambda bot: rg.wdist(bot.location, center)) adjacent_bots = [] for enemy in enemy_bots: if rg.wdist(enemy.location, self.location) == 1: adjacent_bots.append(enemy) if len(adjacent_bots) > self.hp / 9: return ['suicide'] elif adjacent_bots: return ['attack', min(adjacent_bots, key=lambda b: b.hp).location] adj = rg.locs_around(target.location, filter_out=('invalid', 'obstacle')) closest_locs = min(rg.wdist(loc, self.location) for loc in adj) dests = [ loc for loc in adj if rg.wdist(loc, self.location) == closest_locs ] dest = random.choice(dests) if rg.wdist(target.location, self.location) == 1: return ['attack', target.location] else: return ['move', rg.toward(self.location, dest)]
def act(self, game): us, them = process_game(game, self.player_id) x = int(sum([x[0] for x in us]) / len(us)) y = int(sum([y[1] for y in us]) / len(us)) if self.location == (x, y): return ['guard'] enemies_around = list() friends_around = list() for each in them: if rg.dist(self.location, each) == 1: enemies_around.append(each) for each in us: if rg.dist(self.location, each) == 1: friends_around.append(each) if len(friends_around) >= 3: return ['guard'] distance_border = min([ rg.wdist(place, self.location) for place in rg.settings.spawn_coords ]) if len(friends_around) >= 2 and distance_border > 3: return ['guard'] if len(enemies_around) >= 2: return ['suicide'] if self.hp < 8 and enemies_around: return ['suicide'] for each in them: if rg.dist(self.location, each) == 1: if test_location(each): return ['attack', each] if test_location((x, y)): return ['move', rg.toward(self.location, (x, y))] return ['guard']
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]
def next_move(self, destination, game): print "next_move!" def is_valid_and_safe(step): for unsafe_type in ['invalid', 'spawn', 'obstacle']: if unsafe_type in rg.loc_types(step): print "unsafe_type:", unsafe_type return False return True def is_friendly(step, game): for loc, robot in self.friendly_list(game): if loc == step: print "is_friendly:", True return True return False test_step = rg.toward(self.location, destination) if is_valid_and_safe(test_step) and not is_friendly(test_step,game): return test_step print "not OK from: %s to test_step: %s"%(self.location, test_step) #move clockwize move_mask = (test_step[1]-self.location[1], test_step[0]-self.location[0]) next_step = (self.location[0]+move_mask[0], self.location[1]+move_mask[1]) print "mask: %s, next_step: %s"%(move_mask, next_step) return next_step
def act(self, game): # Find nearest enemy enemies = {} nearest_enemy = (1000000, rg.CENTER_POINT) for loc, bot in game.robots.iteritems(): if bot.player_id != self.player_id: enemies[loc] = bot distance = rg.dist(loc, self.location) if distance < nearest_enemy[0]: nearest_enemy = (distance, loc) # If nearest enemy is next to us, ATTACK or KABOOM! if nearest_enemy[0] <= 1: potential_suicide_damage = 0 for loc in rg.locs_around(self.location): if loc in enemies: potential_suicide_damage += min(15, enemies[loc].hp) if self.hp < potential_suicide_damage: return ['suicide'] else: return ['attack', nearest_enemy[1]] # If we cannot move, defend. desired_move = rg.toward(self.location, nearest_enemy[1]) if rg.loc_types(desired_move) in ['obstacle', 'invalid']: return ['guard'] # Otherwise, advance on the enemy without mercy return ['move', desired_move]
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)]
def act(self, game): # Move out of spawning zone if 'spawn' in rg.loc_types(self.location): loc = self.get_open_adjacent(game) if loc: return ['move', loc] else: # All adjacent are occupied, or still in the spawning zone. loc = self.get_open_adjacent(game, spawnok=True) if loc: return ['move', loc] # Find an enemy loc, d = self.get_closest_enemy(game) if d < 0: # The are no enemies return ['guard'] elif d <= 1: # Enemy within range if self.is_worth_dying(game): return ['suicide'] return ['attack', loc] else: # Enemy out of range closer = rg.toward(self.location, loc) if can_move(closer, game): return ['move', closer] loc = self.get_open_adjacent(game) if loc: return ['move', loc] return ['guard']
def act(self, game): num_enemies = self.num_enemies(game) if num_enemies * 9 > self.hp: return ['suicide'] min_distance = float("inf") move_to = self.get_center(game) 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 = self.get_center(game) if self.location == self.get_center(game): return ['guard'] if self.num_frieds(game) > 1: return ['guard'] return ['move', rg.toward(self.location, move_to)]
def otherwise(self, game, current_return): if current_return != ['empty']: return current_return if self.location != rg.CENTER_POINT: towards_center = rg.toward(self.location, rg.CENTER_POINT) return ['move', towards_center] else: return ['guard']
def strong_enemy(self, game): hp = 0 for loc, bot in game.get('robots').items(): if bot.player_id != self.player_id: if bot.hp > hp: hp = bot.hp l = loc return self.plan_move(game, rg.toward(self.location, l))
def act(self, game): # 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 # for loc, bot in game.robots.iteritems(): # if bot.player_id != self.player_id: # if rg.dist(loc, self.location) <= 1: # return ['attack', loc] wejscia = {loc for loc in wszystkie if 'spawn' in rg.loc_types(loc)} sasiednie = set(rg.locs_around(self.location)) - zablokowane sasiednie_wrogowie = sasiednie & wrogowie if sasiednie_wrogowie: if 9 * len(sasiednie_wrogowie) < self.hp: return ['attack', sasiednie_wrogowie.pop()] if self.location in wejscia: move = ['move', rg.toward(self.location, rg.CENTER_POINT)] if self.location == rg.CENTER_POINT: return ['guard'] return ['move', rg.toward(self.location, rg.CENTER_POINT)]
def act(self, game): if 'spawn' in rg.loc_types(self.location): return ['move', rg.toward(self.location, rg.CENTER_POINT)] my_friendly_neighbours = self.get_neighbours(game) if my_friendly_neighbours: return ['move', rg.toward(self.location, rg.CENTER_POINT)] bad_neighbours = self.get_neighbours(game, friendly=False, onlyspawn=False) # CAMP THE SPAWN! SHOOT NOW! shoot = 'attack' if bad_neighbours: if random.randint(0, 10) > 7: print('HAHAHA! DIE DIE DIE!') return [shoot, bad_neighbours[0]['location']] return ['guard']
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 for wrog in wrogowie: if rg.wdist(poz, self.location) == 2: # ruch = działanie xD # 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 if len(wrogowie_obok) > 2 and self.hp < 27: ruch = ['suicide'] else wrogowie_obok: ruch = ['attack', wrogowie_obok.pop()] return ruch
def act(self, game): # list of distances to the enemy bots and their locations enemy_dist_and_locs = [(rg.dist(loc, self.location), loc) for loc, bot in game.robots.iteritems() if bot.player_id != self.player_id] # sort by distance. enemy_dist_and_locs.sort() neighbours = [(dist, loc) for dist, loc in enemy_dist_and_locs[:4] if dist <= 1] # try to escape from spawn location # (this is buggy) if (game.turn + 1) % 10 and rg.loc_types(self.location) == "spawn": location = rg.toward(self.location, rg.CENTER_POINT) if location in game.robots: return ["suicide"] else: return ["move", location] # commit suicide if surrounded and likely to die soon if len(neighbours) >= 2 and self.hp < 1 + len(neighbours) * 10: return ["suicide"] # choose an enemy to destroy for dist, loc in enemy_dist_and_locs: # attack if close if dist == 1: self.new_locs[self.robot_id] = self.location return ["attack", loc] # move if no other robot is moving into the same position move_towards = rg.toward(self.location, loc) for key, value in self.new_locs.items(): if value == move_towards and key != self.robot_id: break else: self.new_locs[self.robot_id] = move_towards return ["move", move_towards] # if you can"t attack or move near an enemy, guard return ["guard"]
def act(self, game): dystans = rg.dist(self.location, rg.CENTER_POINT) #print dystans if dystans >= 7: return ['move', rg.toward(self.location, rg.CENTER_POINT)] # idź do środka planszy, ruch domyślny #return ['move', rg.toward(self.location, rg.CENTER_POINT)] return ['guard']
def flee_spawn(self): turn = self.game.turn % 10 spawn_time = turn == 0 or turn == 9 or turn == 8 # if in spawn point near spawn time, move towards centre if spawn_time and self.game.turn < 95 and self.is_spawn(self.location): return ['move', rg.toward(self.location, rg.CENTER_POINT)] else: return None
def act(self, game): wrogowie = self.znajdz_wrogow_obok(game) print(wrogowie) if len(wrogowie) == 1 and self.hp > 10: return ['attack', wrogowie[0]] if self.location != rg.CENTER_POINT: return ['move', rg.toward(self.location, rg.CENTER_POINT)] return ['guard']
def act(self, game): # if we're in the center, stay put 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 to un occupied spot locs = rg.locs_around(self.location, filter_out=('invalid', 'obstacle')) if rg.toward(self.location, rg.CENTER_POINT) in locs: return ['move', rg.toward(self.location, rg.CENTER_POINT)] else: if len(locs)>=1: return ['move', locs(0)] else: return ['guard']
def act(self, game): wrogowie = [] for poz in rg.locs_around(self.location, filter_out('invalid', 'obstacle')): if game.robots.get(poz) and \ game.robots[poz].player_id != self.player_id: wrogowie.append(poz) if self.location != rg.CENTER_POINT: return ['move', rg.toward(self.location, rg.CENTER_POINT)] return ['guard']
def weak_enemy(self, game): hp = None l = None for loc, bot in game.get('robots').items(): if bot.player_id != self.player_id: if None == hp: hp = bot.hp l = loc elif bot.hp < hp: hp = bot.hp l = loc return self.plan_move(game, rg.toward(self.location, l))
def act(self, game): # If we're on a spawn square, get out if rg.loc_types(self.loc) != 'normal': return ['move', rg.toward(self.location, rg.CENTER_POINT)] d1_us = {} d1_them = {} d2_us = {} d2_them = {} for loc, bot in game.robots.iteritems(): if rg.wdist(self.loc, loc) == 1: if bot.robot_id: d1_us[loc] = bot else: d1_them[loc] = bot elif rg.wdist(self.loc, loc) == 2: if bot.robot_id: d2_us[loc] = bot else: d2_them[loc] = bot if d1_them: return ['attack', d1_them.keys()[0]] elif d2_them: return ['attack', rg.toward(self.loc, d2_them.keys()[0])] # move: # - don't move into a square an ally could move into # - move towards an ally # - move towards an enemy # suicide condition #allyNeighbours = 0 # work out #enemyNeightbours = 0 #if self.hp < 10 and allyNeighbours == 0 and (enemyNeightbours > 1 or enemyNeightbours == 1 and their hp > 10) # return ['suicide'] # Default action #return ['guard'] return ['move', rg.toward(self.location, rg.CENTER_POINT)]