def bored_tactics(self, things, t): # some useful data about the enemies I can see in the map friends = [ thing for thing in things.values() if thing.team == self.team and thing != self ] enemy_team = settings.ENEMY_TEAMS[self.team] enemy_ancient = [ thing for thing in things.values() if thing.team == enemy_team and thing.name == 'ancient' ][0] enemy_heroes = [ thing for thing in things.values() if thing.team == enemy_team and thing.name not in ('tower', 'ancient', 'creep') ] bravest_friend = closest(enemy_ancient, friends) closest_friend = closest(self, friends) if self.life < self.max_life * 0.8 and enemy_heroes and self.life < enemy_heroes[ 0].life * 1.2: # go to friends moves = sort_by_distance(closest_friend, possible_moves(self, things)) else: moves = sort_by_distance(bravest_friend, possible_moves(self, things)) if moves: return 'move', moves[0] """
def act(self, things, t): enemy_team = settings.ENEMY_TEAMS[self.team] enemies = [thing for thing in things.values() if thing.team == enemy_team] closest_enemy = closest(self, enemies) closest_enemy_distance = distance(self, closest_enemy) if closest_enemy_distance <= settings.CREEP_ATTACK_DISTANCE: # enemy in range, attack! return 'attack', closest_enemy.position else: if closest_enemy_distance > settings.CREEP_AGGRO_DISTANCE: # enemy too far away, go to the ancient enemy_ancient = [thing for thing in enemies if isinstance(thing, Ancient)][0] move_target = enemy_ancient else: # enemy in aggro distance, go to it! move_target = closest_enemy moves = sort_by_distance(move_target, possible_moves(self, things)) for move in moves: return 'move', move return None
def simple_hero_logic(self, things, t): # some useful data about the enemies I can see in the map enemy_team = settings.ENEMY_TEAMS[self.team] enemies = [thing for thing in things.values() if thing.team == enemy_team] closest_enemy = closest(self, enemies) closest_enemy_distance = distance(self, closest_enemy) if self.life < self.max_life and self.can('heal', t): # if I'm hurt and can heal, heal return 'heal', self.position else: # else, try to attack if closest_enemy: # there is an enemy if closest_enemy_distance < settings.STUN_DISTANCE and self.can('stun', t): # try to stun him return 'stun', closest_enemy.position elif closest_enemy_distance < settings.FIREBALL_DISTANCE and self.can('fireball', t) and closest_enemy_distance > settings.FIREBALL_RADIUS: # else try to fireball him, but only if I'm not in range return 'firebal', closest_enemy.position elif closest_enemy_distance < settings.HERO_ATTACK_DISTANCE: # else try to attack him return 'attack', closest_enemy.position else: # of finally just move to him moves = sort_by_distance(closest_enemy, possible_moves(self, things)) for move in moves: return 'move', move else: # no enemies, do nothing return None
def lenovo_hero_logic(self, things, t): # some useful data about the enemies I can see in the map enemy_team = settings.ENEMY_TEAMS[self.team] enemies = [ thing for thing in things.values() if thing.team == enemy_team ] closest_enemy = closest(self, enemies) closest_enemy_distance = distance(self, closest_enemy) real_life = ((self.life / self.max_life) * 100) # now lets decide what to do if int(real_life) < 75 and self.can('heal', t): # if I'm hurt and can heal, heal if closest_enemy_distance <= settings.HEAL_DISTANCE and self.can( 'fireball', t): return 'fireball', closest_enemy.position elif closest_enemy_distance <= settings.HEAL_DISTANCE and self.can( 'stun', t): return 'stun', closest_enemy.position elif closest_enemy_distance <= settings.HEAL_DISTANCE and self.can( 'attack', t): return 'attack', closest_enemy.position elif self.can('heal', t): return 'heal', self.position else: return 'move', (self.position[0] - 1, self.position[1] - 1) else: # else, try to attack if closest_enemy: # there is an enemy if closest_enemy_distance <= settings.STUN_DISTANCE and self.can( 'stun', t): # try to stun him return 'stun', closest_enemy.position if closest_enemy_distance <= settings.FIREBALL_DISTANCE and self.can( 'fireball', t ) and closest_enemy_distance > settings.FIREBALL_RADIUS: # else try to fireball him, but only if I'm not in range return 'fireball', closest_enemy.position elif closest_enemy_distance <= settings.HERO_ATTACK_DISTANCE: # else try to attack him return 'attack', closest_enemy.position else: # of finally just move to him (if I have life > 50) moves = sort_by_distance(closest_enemy, possible_moves(self, things)) if len(moves) > 0: back_moves = moves[len(moves) - 1] else: back_moves = self.position if moves and int(real_life) > 50: return 'move', moves[0] else: return 'move', back_moves # can't do the things I want. Do nothing. return 'fireball', closest_enemy.position
def lenovo_hero_logic(self, things, t): # some useful data about the enemies I can see in the map enemy_team = settings.ENEMY_TEAMS[self.team] enemies = [thing for thing in things.values() if thing.team == enemy_team] closest_enemy = closest(self, enemies) closest_enemy_distance = distance(self, closest_enemy) real_life = ((self.life / self.max_life) * 100) # now lets decide what to do if int(real_life) < 75 and self.can('heal', t): # if I'm hurt and can heal, heal if closest_enemy_distance <= settings.HEAL_DISTANCE and self.can('fireball', t): return 'fireball', closest_enemy.position elif closest_enemy_distance <= settings.HEAL_DISTANCE and self.can('stun', t): return 'stun', closest_enemy.position elif closest_enemy_distance <= settings.HEAL_DISTANCE and self.can('attack', t): return 'attack', closest_enemy.position elif self.can('heal', t): return 'heal', self.position else: return 'move', (self.position[0]-1, self.position[1]-1) else: # else, try to attack if closest_enemy: # there is an enemy if closest_enemy_distance <= settings.STUN_DISTANCE and self.can('stun', t): # try to stun him return 'stun', closest_enemy.position if closest_enemy_distance <= settings.FIREBALL_DISTANCE and self.can('fireball', t) and closest_enemy_distance > settings.FIREBALL_RADIUS: # else try to fireball him, but only if I'm not in range return 'fireball', closest_enemy.position elif closest_enemy_distance <= settings.HERO_ATTACK_DISTANCE: # else try to attack him return 'attack', closest_enemy.position else: # of finally just move to him (if I have life > 50) moves = sort_by_distance(closest_enemy, possible_moves(self, things)) if len(moves) > 0: back_moves = moves[len(moves)-1] else: back_moves = self.position if moves and int(real_life) > 50: return 'move', moves[0] else: return 'move', back_moves # can't do the things I want. Do nothing. return 'fireball', closest_enemy.position
def bored_tactics(self, things, t): # some useful data about the enemies I can see in the map friends = [thing for thing in things.values() if thing.team == self.team and thing != self] enemy_team = settings.ENEMY_TEAMS[self.team] enemy_ancient = [thing for thing in things.values() if thing.team == enemy_team and thing.name == 'ancient'][0] enemy_heroes = [thing for thing in things.values() if thing.team == enemy_team and thing.name not in ('tower', 'ancient', 'creep')] bravest_friend = closest(enemy_ancient, friends) closest_friend = closest(self, friends) if self.life < self.max_life * 0.8 and enemy_heroes and self.life < enemy_heroes[0].life * 1.2: # go to friends moves = sort_by_distance(closest_friend, possible_moves(self, things)) else: moves = sort_by_distance(bravest_friend, possible_moves(self, things)) if moves: return 'move', moves[0] """
def predict_move(item, things, t): if item.name in ('tree', 'tower', 'ancient'): # These not move return [item.position] elif item.disabled_until > t: # Disabled does not move return [item.position] else: # CREEPS # heros are assumed to be creep-like # Copy and paste from things.py enemy_team = settings.ENEMY_TEAMS[item.team] enemies = [ thing for thing in things.values() if thing.team == enemy_team ] closest_enemy = closest(item, enemies) closest_enemy_distance = distance(item, closest_enemy) if closest_enemy_distance <= settings.CREEP_ATTACK_DISTANCE: return [item.position] else: if closest_enemy_distance > settings.CREEP_AGGRO_DISTANCE: # enemy too far away, go to the ancient enemy_ancient = [ thing for thing in enemies if thing.name == 'ancient' ][0] move_target = enemy_ancient else: # enemy in aggro distance, go to it! move_target = closest_enemy moves = sort_by_distance(move_target, possible_moves(item, things)) if not moves: return [item.position] elif len(moves) == 1: return [moves[0]] else: if distance(moves[0], move_target) == distance(moves[1], move_target): return moves[:2] else: return moves[:1] return [item.position]
def predict_move(item, things, t): if item.name in ('tree', 'tower', 'ancient'): # These not move return [item.position] elif item.disabled_until > t: # Disabled does not move return [item.position] else: # CREEPS # heros are assumed to be creep-like # Copy and paste from things.py enemy_team = settings.ENEMY_TEAMS[item.team] enemies = [thing for thing in things.values() if thing.team == enemy_team] closest_enemy = closest(item, enemies) closest_enemy_distance = distance(item, closest_enemy) if closest_enemy_distance <= settings.CREEP_ATTACK_DISTANCE: return [item.position] else: if closest_enemy_distance > settings.CREEP_AGGRO_DISTANCE: # enemy too far away, go to the ancient enemy_ancient = [thing for thing in enemies if thing.name=='ancient'][0] move_target = enemy_ancient else: # enemy in aggro distance, go to it! move_target = closest_enemy moves = sort_by_distance(move_target, possible_moves(item, things)) if not moves: return [item.position] elif len(moves) == 1: return [moves[0]] else: if distance(moves[0], move_target) == distance(moves[1], move_target): return moves[:2] else: return moves[:1] return [item.position]
def simple_hero_logic(self, things, t): # some useful data about the enemies I can see in the map enemy_team = settings.ENEMY_TEAMS[self.team] enemies = [ thing for thing in things.values() if thing.team == enemy_team ] closest_enemy = closest(self, enemies) closest_enemy_distance = distance(self, closest_enemy) # now lets decide what to do if self.life < self.max_life and self.can('heal', t): # if I'm hurt and can heal, heal return 'heal', self.position else: # else, try to attack if closest_enemy: # there is an enemy if closest_enemy_distance <= settings.STUN_DISTANCE and self.can( 'stun', t): # try to stun him return 'stun', closest_enemy.position elif closest_enemy_distance <= settings.FIREBALL_DISTANCE and self.can( 'fireball', t ) and closest_enemy_distance > settings.FIREBALL_RADIUS: # else try to fireball him, but only if I'm not in range return 'fireball', closest_enemy.position elif closest_enemy_distance <= settings.HERO_ATTACK_DISTANCE: # else try to attack him return 'attack', closest_enemy.position else: # of finally just move to him moves = sort_by_distance(closest_enemy, possible_moves(self, things)) if moves: return 'move', moves[0] # can't do the things I want. Do nothing. return None
def simple_hero_logic(self, things, t): # some useful data about the enemies I can see in the map enemy_team = settings.ENEMY_TEAMS[self.team] enemies = [thing for thing in things.values() if thing.team == enemy_team] closest_enemy = closest(self, enemies) closest_enemy_distance = distance(self, closest_enemy) # now lets decide what to do if self.life < self.max_life and self.can("heal", t): # if I'm hurt and can heal, heal return "heal", self.position else: # else, try to attack if closest_enemy: # there is an enemy if closest_enemy_distance <= settings.STUN_DISTANCE and self.can("stun", t): # try to stun him return "stun", closest_enemy.position elif ( closest_enemy_distance <= settings.FIREBALL_DISTANCE and self.can("fireball", t) and closest_enemy_distance > settings.FIREBALL_RADIUS ): # else try to fireball him, but only if I'm not in range return "fireball", closest_enemy.position elif closest_enemy_distance <= settings.HERO_ATTACK_DISTANCE: # else try to attack him return "attack", closest_enemy.position else: # of finally just move to him moves = sort_by_distance(closest_enemy, possible_moves(self, things)) if moves: return "move", moves[0] # can't do the things I want. Do nothing. return None
def pulenta_hero_logic(self, things, t): # some useful data about the enemies I can see in the map enemy_team = ENEMY_TEAMS[self.team] enemies = [ thing for thing in things.values() if thing.team == enemy_team ] closest_enemy = closest(self, enemies) closest_enemy_distance = distance(self, closest_enemy) # now lets decide what to do if self.can('heal', t) and self.life < self.max_life: # if I'm hurt and can heal, heal return 'heal', self.position else: # else, try to attack if closest_enemy: if closest_enemy_distance <= STUN_DISTANCE and self.can( 'stun', t): # try to stun him return 'stun', closest_enemy.position elif FIREBALL_RADIUS < closest_enemy_distance <= FIREBALL_DISTANCE \ and self.can('fireball', t): # else try to fireball him, but only if I'm not in range return 'fireball', closest_enemy.position elif closest_enemy_distance <= HERO_ATTACK_DISTANCE: # else try to attack him return 'attack', closest_enemy.position # elif closest_enemy_distance < settings.STUN_DISTANCE and self.can('stun', t): # # try to stun him # return 'stun', closest_enemy.position # else: # of finally just move to him else: their_base = [ thing for thing in things.values() if thing.team == enemy_team and isinstance(thing, Ancient) ][0] my_tower = [ thing for thing in things.values() if thing.team == self.team and isinstance(thing, Tower) ] my_team = [ thing for thing in things.values() if thing.team == self.team and isinstance(thing, Creep) ] closest_to_base = closest(their_base, my_team) my_team_wo_closest = [ thing for thing in things.values() if thing.team == self.team and isinstance( thing, Creep) and thing != closest_to_base ] snd_closest_to_base = closest(their_base, my_team_wo_closest) enemies_close = [ thing for thing in things.values() if thing.team == enemy_team and (isinstance(thing, Creep) or isinstance(thing, Hero)) and distance(thing, their_base) < distance( self, their_base) ] #my_team_pos = map(lambda x: x.position, my_team) team_reference = snd_closest_to_base if snd_closest_to_base is not None \ else closest_to_base if self.max_life < 300: if my_tower: my_tower = my_tower[0] element = my_tower else: element = team_reference # elif len(enemies_close) > 2: # element = snd_closest_to_base elif distance(their_base, team_reference) > distance( their_base, self): if len(enemies_close) > 2: element = team_reference elif len(enemies_close) > 1: return None else: element = their_base else: element = their_base # else: # element = [thing for thing in things.values() # if thing.team == enemy_team and isinstance(thing, Ancient)][0] moves = sort_by_distance(element, possible_moves(self, things)) if moves: return 'move', moves[0] return None
def move_to_target(hero, target, things): moves = sort_by_distance(target, possible_moves(hero, things)) action = None if len(moves) > 0: action = 'move', moves[0] return action
def logic(self, things, t): #For fun #self.xp = 1000000 #Enemies enemy_team = settings.ENEMY_TEAMS[self.team] enemies = [ thing for thing in things.values() if thing.team == enemy_team ] closest_enemy = closest(self, enemies) closest_enemy_distance = distance(self, closest_enemy) enemy_ancient = [ thing for thing in enemies if isinstance(thing, Ancient) ][0] try: enemy_tower = [ thing for thing in enemies if isinstance(thing, Tower) ][0] except: pass closest_enemy_distance = distance(self, closest_enemy) #Friends friends = [ thing for thing in things.values() if thing.team == self.team ] friendly_creeps = [ friend for friend in friends if isinstance(friend, Creep) ] closest_friend_creep = closest(self, friendly_creeps) friendly_ancient = [ thing for thing in friends if isinstance(thing, Ancient) ][0] #Utils #Act life_factor = (self.level + 1) life_comparer = self.max_life - (self.max_life * (life_factor / 100)) life_comparer = life_comparer if life_comparer >= 0 else self.max_life if self.life < life_comparer or self.life < self.max_life * 0.30: if self.can('heal', t): return 'heal', self.position else: target_to_go = closest_friend_creep if closest_friend_creep else friendly_ancient moves = sort_by_distance(target_to_go, possible_moves(self, things)) for move in moves: return 'move', move elif closest_enemy: if closest_enemy_distance <= settings.STUN_DISTANCE and self.can( 'stun', t): return 'stun', closest_enemy.position elif closest_enemy_distance <= settings.FIREBALL_DISTANCE and self.can( 'fireball', t) and closest_enemy_distance > settings.FIREBALL_RADIUS: return 'fireball', closest_enemy.position elif closest_enemy_distance <= settings.HERO_ATTACK_DISTANCE: return 'attack', closest_enemy.position else: moves = sort_by_distance(closest_enemy, possible_moves(self, things)) if moves: return 'move', moves[0] else: moves = sort_by_distance(friendly_creeps[-1], possible_moves(self, things)) for move in moves: return 'move', move
def rush_hero_logic(self, things, t): enemy_team = settings.ENEMY_TEAMS[self.team] enemies = [ thing for thing in things.values() if thing.team == enemy_team ] closest_enemy = closest(self, enemies) closest_enemy_distance = distance(self, closest_enemy) enemy_ancient = [e for e in enemies if e.name == 'ancient'][0] enemy_tower = None enemy_tower = [e for e in enemies if e.name == 'tower'] if enemy_tower: enemy_tower = enemy_tower[0] enemy_hero = None enemy_heroes = [e for e in enemies if isinstance(e, Hero)] if enemy_heroes: enemy_hero = closest(self, enemy_heroes) friends = [ thing for thing in things.values() if thing.team == self.team and thing != self ] friendly_ancient = [e for e in friends if e.name == 'ancient'][0] back_friends = sort_by_distance(self, friends)[2:] closest_friend = closest(self, friends) closest_friend_distance = distance(self, closest_friend) full_path_distance = distance(enemy_ancient, friendly_ancient) offside = closest(enemy_ancient, back_friends + [self]) == self # enemy units behind me enemy_offside = closest(friendly_ancient, enemies + [self]) != self # if I can stun the other hero, that's highest priority if closest_enemy and closest_enemy == enemy_hero\ and closest_enemy_distance <= settings.STUN_DISTANCE and self.can('stun', t): # try to stun him log('stun !!!', t) return 'stun', closest_enemy.position surrounding_damage = 0 heal_effect = calculate_damage(self, settings.HEAL_BASE_HEALING, settings.HEAL_LEVEL_MULTIPLIER) heal_targets = [ f for f in friends + [self] \ if distance(self, f) <= settings.HEAL_RADIUS ] for friend in heal_targets: surrounding_damage += friend.max_life - friend.life # maximize heal effect if self.can('heal', t) and surrounding_damage >= heal_effect: log("heal", t) return 'heal', self.position # if I'm at the enemy ancient, prioritize attacking it if closest_enemy and closest_enemy == enemy_ancient\ and distance(self, closest_enemy) <= settings.HERO_ATTACK_DISTANCE: fireball_damage = calculate_damage( self, settings.FIREBALL_BASE_DAMAGE, settings.FIREBALL_LEVEL_MULTIPLIER) if self.can('fireball', t) and enemy_ancient.life <= fireball_damage: log('FIREBALL FINISH!!!!!!!!!!!', t) return 'fireball', closest_enemy.position else: return 'attack', closest_enemy.position rush_trigger = max([200, self.max_life / 2]) # get cover if I'm low on energy if offside and self.life < rush_trigger: moves = sort_by_distance(friendly_ancient, valid_positions(self, things)) return 'move', moves[0] if enemies: if enemy_tower and safe_fireball(self, enemy_tower, closest_friend, t): # fireball the tower if in range log("fireball TOWER !!!", t) return 'fireball', enemy_tower.position else: fball_targets = [ e for e in enemies\ if distance(self, e) <= settings.FIREBALL_DISTANCE ] fball_friendlies = [ f for f in friends\ if distance(self, f) <= settings.FIREBALL_DISTANCE ] if fball_targets: # choose the furthest enemy within fireball range best_fball_target = sort_by_distance(self, fball_targets)[-1] if safe_fireball(self, best_fball_target, closest_friend, t): log("fireball", t) return 'fireball', best_fball_target.position if closest_enemy_distance <= settings.HERO_ATTACK_DISTANCE: # log("attack", t) return 'attack', closest_enemy.position else: if enemy_tower: if distance(self, enemy_tower) < settings.FIREBALL_DISTANCE: log("halt", t) return moves = sort_by_distance(enemy_ancient, valid_positions(self, things)) return 'move', moves[0]
def logic(self, things, t): #For fun #self.xp = 1000000 #Enemies enemy_team = settings.ENEMY_TEAMS[self.team] enemies = [thing for thing in things.values() if thing.team == enemy_team] closest_enemy = closest(self, enemies) closest_enemy_distance = distance(self, closest_enemy) enemy_ancient = [thing for thing in enemies if isinstance(thing, Ancient)][0] try: enemy_tower = [thing for thing in enemies if isinstance(thing, Tower)][0] except: pass closest_enemy_distance = distance(self, closest_enemy) #Friends friends = [thing for thing in things.values() if thing.team == self.team] friendly_creeps = [friend for friend in friends if isinstance(friend, Creep)] closest_friend_creep = closest(self, friendly_creeps) friendly_ancient = [thing for thing in friends if isinstance(thing, Ancient)][0] #Utils #Act life_factor = (self.level + 1) life_comparer = self.max_life - (self.max_life * (life_factor / 100)) life_comparer = life_comparer if life_comparer >= 0 else self.max_life if self.life < life_comparer or self.life < self.max_life * 0.30: if self.can('heal', t): return 'heal', self.position else: target_to_go = closest_friend_creep if closest_friend_creep else friendly_ancient moves = sort_by_distance(target_to_go, possible_moves(self, things)) for move in moves: return 'move', move elif closest_enemy: if closest_enemy_distance <= settings.STUN_DISTANCE and self.can('stun', t): return 'stun', closest_enemy.position elif closest_enemy_distance <= settings.FIREBALL_DISTANCE and self.can('fireball', t) and closest_enemy_distance > settings.FIREBALL_RADIUS: return 'fireball', closest_enemy.position elif closest_enemy_distance <= settings.HERO_ATTACK_DISTANCE: return 'attack', closest_enemy.position else: moves = sort_by_distance(closest_enemy, possible_moves(self, things)) if moves: return 'move', moves[0] else: moves = sort_by_distance(friendly_creeps[-1], possible_moves(self, things)) for move in moves: return 'move', move
def matuuuuu_logic(self, things, t): nonlocal ENEMY_HERO_XP enemy_team = settings.ENEMY_TEAMS[self.team] enemies = [ene for ene in things.values() if ene.team == enemy_team] friends = [ thing for thing in things.values() if thing.team == self.team ] closest_enemy = closest(self, enemies) closest_enemy_distance = distance(self, closest_enemy) closest_enemy_hero = closest( self, [x for x in enemies if isinstance(x, Hero)]) if closest_enemy_hero: closest_enemy_hero_distance = distance(self, closest_enemy_hero) enemy_ancient = [ thing for thing in enemies if isinstance(thing, Ancient) ] if enemy_ancient: enemy_ancient = enemy_ancient[0] my_ancient = [thing for thing in friends if isinstance(thing, Ancient)] if my_ancient: my_ancient = my_ancient[0] my_tower = [thing for thing in friends if isinstance(thing, Tower)] if my_tower: my_tower = my_tower[0] enemy_tower = [thing for thing in enemies if isinstance(thing, Tower)] if enemy_tower: enemy_tower = enemy_tower[0] friends_creep = [ thing for thing in friends if isinstance(thing, Creep) ] if self.can('heal', t): if (self.life < self.max_life and is_older(self.position, friends, enemies, settings.HEAL_RADIUS)) \ or self.life < (self.max_life * 0.75): return 'heal', self.position if closest_enemy or closest_enemy_hero: if closest_enemy_hero: if closest_enemy_hero_distance <= settings.STUN_DISTANCE and self.can( 'stun', t): return 'stun', closest_enemy_hero.position if (self.can('fireball', t)): def throw_fireball(me, ce): if distance(me, ce) <= settings.FIREBALL_DISTANCE and distance(me, ce) > settings.FIREBALL_RADIUS and \ is_older(ce, enemies, friends, settings.FIREBALL_RADIUS): return 'fireball', ce.position temp_enemies = enemies for i in range(3): temp_enemy = closest(self, temp_enemies) if temp_enemy: throw_fireball(self, temp_enemy) temp_enemies = [ ene for ene in temp_enemies if ene != temp_enemy ] else: break if closest_enemy_distance <= settings.HERO_ATTACK_DISTANCE: return 'attack', closest_enemy.position else: moves = None if self.xp > 4 and ENEMY_HERO_XP > 2 and self.xp // 2 >= ENEMY_HERO_XP: if closest_enemy_hero: ENEMY_HERO_XP = closest_enemy_hero.xp moves = sort_by_distance(closest_enemy_hero, possible_moves(self, things)) elif enemy_tower: moves = sort_by_distance(enemy_tower, possible_moves(self, things)) else: moves = sort_by_distance(enemy_ancient, possible_moves(self, things)) else: if closest_enemy_hero: ENEMY_HERO_XP = closest_enemy_hero.xp if distance(self, my_ancient) > distance( closest_enemy_hero, my_ancient): moves = sort_by_distance( my_ancient, possible_moves(self, things)) elif my_tower and distance(self, my_tower) > distance( closest_enemy_hero, my_tower): moves = sort_by_distance( my_tower, possible_moves(self, things)) if not moves: if my_tower: friends_creep.append(my_tower) moves = sort_by_distance( media_position(friends_creep, my_tower.position), possible_moves(self, things)) else: moves = sort_by_distance( media_position(friends_creep, my_ancient.position), possible_moves(self, things)) if moves: return 'move', moves[0] else: if enemy_tower: moves = sort_by_distance(enemy_tower, possible_moves(self, things)) else: moves = sort_by_distance(enemy_ancient, possible_moves(self, things)) if moves: return 'move', moves[0] elif self.life < self.max_life and self.can('heal', t): return 'heal', self.position return None
def rush_hero_logic(self, things, t): enemy_team = settings.ENEMY_TEAMS[self.team] enemies = [ thing for thing in things.values() if thing.team == enemy_team ] enemy_ancient = [e for e in enemies if e.name == 'ancient'][0] enemy_tower = [e for e in enemies if e.name == 'tower'] if enemy_tower: enemy_tower = enemy_tower[0] enemy_hero = [e for e in enemies if e.__class__.__name__ == "Hero"] if enemy_hero: enemy_hero = enemy_hero[0] closest_enemy = closest(self, enemies) closest_enemy_distance = distance(self, closest_enemy) friends = [ thing for thing in things.values() if thing.team == self.team and thing != self ] friendly_ancient = [e for e in friends if e.name == 'ancient'][0] back_friends = sort_by_distance(self, friends)[2:] closest_friend = closest(self, friends) closest_friend_distance = distance(self, closest_friend) # I'm offside if there are not at least 2 friendlies in front of me offside = closest(enemy_ancient, back_friends + [self]) == self # There are enemy units behind me enemy_offside = closest(friendly_ancient, enemies + [self]) != self # log("offside: "+ str(offside)) # log("friend: %s, enemy: %s" % (str(closest_friend), str(closest_enemy))) # if I can stun the other hero, that's highest priority if closest_enemy and closest_enemy == enemy_hero\ and closest_enemy_distance <= settings.STUN_DISTANCE and self.can('stun', t): # try to stun him log('stun !!!') return 'stun', closest_enemy.position # move to get conver if I'm low on energy or there's an enemy behind me if (offside and self.life < 200): # or enemy_offside: moves = sort_by_distance(friendly_ancient, valid_positions(self, things)) return 'move', moves[0] if self.life < (self.max_life - settings.HEAL_BASE_HEALING[1]) and self.can('heal', t)\ and (closest_friend and closest_friend_distance <= settings.HEAL_DISTANCE): log("heal") return 'heal', self.position else: if closest_enemy: # there is an enemy # if closest_enemy_distance <= settings.FIREBALL_DISTANCE and self.can('fireball', t) and closest_enemy_distance > settings.FIREBALL_RADIUS and closest_friend_distance > (settings.FIREBALL_DISTANCE + settings.FIREBALL_RADIUS): if self.can('fireball', t) and closest_enemy_distance < settings.FIREBALL_DISTANCE +settings.FIREBALL_RADIUS\ and closest_enemy_distance > settings.FIREBALL_RADIUS\ and distance(closest_friend, closest_enemy) > settings.FIREBALL_RADIUS: # else try to fireball him, but only if I'm not in range log("fireball !!!") return 'fireball', closest_enemy.position elif closest_enemy_distance <= settings.HERO_ATTACK_DISTANCE: # else try to attack him log("attack") return 'attack', closest_enemy.position else: if enemy_tower: if distance(self, enemy_tower) < 5: log("halt") return moves = sort_by_distance(enemy_ancient, valid_positions(self, things)) return 'move', moves[0]
def close(something, others, pos): """Returns the closest other to something (things/positions).""" if others: return sort_by_distance(something, others)[pos]
def matuuuuu_logic(self, things, t): nonlocal ENEMY_HERO_XP enemy_team = settings.ENEMY_TEAMS[self.team] enemies = [ene for ene in things.values() if ene.team == enemy_team] friends = [thing for thing in things.values() if thing.team == self.team] closest_enemy = closest(self, enemies) closest_enemy_distance = distance(self, closest_enemy) closest_enemy_hero = closest(self, [x for x in enemies if isinstance(x, Hero)]) if closest_enemy_hero: closest_enemy_hero_distance = distance(self, closest_enemy_hero) enemy_ancient = [thing for thing in enemies if isinstance(thing, Ancient)] if enemy_ancient: enemy_ancient = enemy_ancient[0] my_ancient = [thing for thing in friends if isinstance(thing, Ancient)] if my_ancient: my_ancient = my_ancient[0] my_tower = [thing for thing in friends if isinstance(thing, Tower)] if my_tower: my_tower = my_tower[0] enemy_tower = [thing for thing in enemies if isinstance(thing, Tower)] if enemy_tower: enemy_tower = enemy_tower[0] friends_creep = [thing for thing in friends if isinstance(thing, Creep)] if self.can('heal', t): if (self.life < self.max_life and is_older(self.position, friends, enemies, settings.HEAL_RADIUS)) \ or self.life < (self.max_life * 0.75): return 'heal', self.position if closest_enemy or closest_enemy_hero: if closest_enemy_hero: if closest_enemy_hero_distance <= settings.STUN_DISTANCE and self.can('stun', t): return 'stun', closest_enemy_hero.position if (self.can('fireball', t)): def throw_fireball(me, ce): if distance(me, ce) <= settings.FIREBALL_DISTANCE and distance(me, ce) > settings.FIREBALL_RADIUS and \ is_older(ce, enemies, friends, settings.FIREBALL_RADIUS): return 'fireball', ce.position temp_enemies = enemies for i in range(3): temp_enemy = closest(self, temp_enemies) if temp_enemy: throw_fireball(self, temp_enemy) temp_enemies = [ene for ene in temp_enemies if ene != temp_enemy] else: break if closest_enemy_distance <= settings.HERO_ATTACK_DISTANCE: return 'attack', closest_enemy.position else: moves = None if self.xp > 4 and ENEMY_HERO_XP > 2 and self.xp//2 >= ENEMY_HERO_XP: if closest_enemy_hero: ENEMY_HERO_XP = closest_enemy_hero.xp moves = sort_by_distance(closest_enemy_hero, possible_moves(self, things)) elif enemy_tower: moves = sort_by_distance(enemy_tower, possible_moves(self, things)) else: moves = sort_by_distance(enemy_ancient, possible_moves(self, things)) else: if closest_enemy_hero: ENEMY_HERO_XP = closest_enemy_hero.xp if distance(self, my_ancient) > distance(closest_enemy_hero, my_ancient): moves = sort_by_distance(my_ancient, possible_moves(self, things)) elif my_tower and distance(self, my_tower) > distance(closest_enemy_hero, my_tower): moves = sort_by_distance(my_tower, possible_moves(self, things)) if not moves: if my_tower: friends_creep.append(my_tower) moves = sort_by_distance(media_position(friends_creep, my_tower.position), possible_moves(self, things)) else: moves = sort_by_distance(media_position(friends_creep, my_ancient.position), possible_moves(self, things)) if moves: return 'move', moves[0] else: if enemy_tower: moves = sort_by_distance(enemy_tower, possible_moves(self, things)) else: moves = sort_by_distance(enemy_ancient, possible_moves(self, things)) if moves: return 'move', moves[0] elif self.life < self.max_life and self.can('heal', t): return 'heal', self.position return None
def pulenta_hero_logic(self, things, t): # some useful data about the enemies I can see in the map enemy_team = ENEMY_TEAMS[self.team] enemies = [thing for thing in things.values() if thing.team == enemy_team] closest_enemy = closest(self, enemies) closest_enemy_distance = distance(self, closest_enemy) # now lets decide what to do if self.can('heal', t) and self.life < self.max_life: # if I'm hurt and can heal, heal return 'heal', self.position else: # else, try to attack if closest_enemy: if closest_enemy_distance <= STUN_DISTANCE and self.can('stun', t): # try to stun him return 'stun', closest_enemy.position elif FIREBALL_RADIUS < closest_enemy_distance <= FIREBALL_DISTANCE \ and self.can('fireball', t): # else try to fireball him, but only if I'm not in range return 'fireball', closest_enemy.position elif closest_enemy_distance <= HERO_ATTACK_DISTANCE: # else try to attack him return 'attack', closest_enemy.position # elif closest_enemy_distance < settings.STUN_DISTANCE and self.can('stun', t): # # try to stun him # return 'stun', closest_enemy.position # else: # of finally just move to him else: their_base = [thing for thing in things.values() if thing.team == enemy_team and isinstance(thing, Ancient)][0] my_tower = [thing for thing in things.values() if thing.team == self.team and isinstance(thing, Tower)] my_team = [thing for thing in things.values() if thing.team == self.team and isinstance(thing, Creep)] closest_to_base = closest(their_base, my_team) my_team_wo_closest = [thing for thing in things.values() if thing.team == self.team and isinstance(thing, Creep) and thing != closest_to_base] snd_closest_to_base = closest(their_base, my_team_wo_closest) enemies_close = [thing for thing in things.values() if thing.team == enemy_team and (isinstance(thing, Creep) or isinstance(thing, Hero)) and distance(thing, their_base) < distance(self, their_base)] #my_team_pos = map(lambda x: x.position, my_team) team_reference = snd_closest_to_base if snd_closest_to_base is not None \ else closest_to_base if self.max_life < 300: if my_tower: my_tower = my_tower[0] element = my_tower else: element = team_reference # elif len(enemies_close) > 2: # element = snd_closest_to_base elif distance(their_base, team_reference) > distance(their_base, self): if len(enemies_close) > 2: element = team_reference elif len(enemies_close) > 1: return None else: element = their_base else: element = their_base # else: # element = [thing for thing in things.values() # if thing.team == enemy_team and isinstance(thing, Ancient)][0] moves = sort_by_distance(element, possible_moves(self, things)) if moves: return 'move', moves[0] return None
def rush_hero_logic(self, things, t): enemy_team = settings.ENEMY_TEAMS[self.team] enemies = [thing for thing in things.values() if thing.team == enemy_team] closest_enemy = closest(self, enemies) closest_enemy_distance = distance(self, closest_enemy) enemy_ancient = [e for e in enemies if e.name == 'ancient'][0] enemy_tower = None enemy_tower = [e for e in enemies if e.name == 'tower'] if enemy_tower: enemy_tower = enemy_tower[0] enemy_hero = None enemy_heroes = [e for e in enemies if isinstance(e, Hero)] if enemy_heroes: enemy_hero = closest(self, enemy_heroes) friends = [thing for thing in things.values() if thing.team == self.team and thing != self] friendly_ancient = [e for e in friends if e.name == 'ancient'][0] back_friends = sort_by_distance(self, friends)[2:] closest_friend = closest(self, friends) closest_friend_distance = distance(self, closest_friend) full_path_distance = distance(enemy_ancient, friendly_ancient) offside = closest(enemy_ancient, back_friends + [self]) == self # enemy units behind me enemy_offside = closest(friendly_ancient, enemies + [self]) != self # if I can stun the other hero, that's highest priority if closest_enemy and closest_enemy == enemy_hero\ and closest_enemy_distance <= settings.STUN_DISTANCE and self.can('stun', t): # try to stun him log('stun !!!', t) return 'stun', closest_enemy.position surrounding_damage = 0 heal_effect = calculate_damage(self, settings.HEAL_BASE_HEALING, settings.HEAL_LEVEL_MULTIPLIER) heal_targets = [ f for f in friends + [self] \ if distance(self, f) <= settings.HEAL_RADIUS ] for friend in heal_targets: surrounding_damage += friend.max_life - friend.life # maximize heal effect if self.can('heal', t) and surrounding_damage >= heal_effect: log("heal", t) return 'heal', self.position # if I'm at the enemy ancient, prioritize attacking it if closest_enemy and closest_enemy == enemy_ancient\ and distance(self, closest_enemy) <= settings.HERO_ATTACK_DISTANCE: fireball_damage = calculate_damage(self, settings.FIREBALL_BASE_DAMAGE, settings.FIREBALL_LEVEL_MULTIPLIER) if self.can('fireball', t) and enemy_ancient.life <= fireball_damage: log('FIREBALL FINISH!!!!!!!!!!!', t) return 'fireball', closest_enemy.position else: return 'attack', closest_enemy.position rush_trigger = max([200, self.max_life/2]) # get cover if I'm low on energy if offside and self.life < rush_trigger: moves = sort_by_distance(friendly_ancient, valid_positions(self, things)) return 'move', moves[0] if enemies: if enemy_tower and safe_fireball(self, enemy_tower, closest_friend, t): # fireball the tower if in range log("fireball TOWER !!!", t) return 'fireball', enemy_tower.position else: fball_targets = [ e for e in enemies\ if distance(self, e) <= settings.FIREBALL_DISTANCE ] fball_friendlies = [ f for f in friends\ if distance(self, f) <= settings.FIREBALL_DISTANCE ] if fball_targets: # choose the furthest enemy within fireball range best_fball_target = sort_by_distance(self, fball_targets)[-1] if safe_fireball(self, best_fball_target, closest_friend, t): log("fireball", t) return 'fireball', best_fball_target.position if closest_enemy_distance <= settings.HERO_ATTACK_DISTANCE: # log("attack", t) return 'attack', closest_enemy.position else: if enemy_tower: if distance(self,enemy_tower) < settings.FIREBALL_DISTANCE: log("halt", t) return moves = sort_by_distance(enemy_ancient, valid_positions(self, things)) return 'move', moves[0]
def rush_hero_logic(self, things, t): enemy_team = settings.ENEMY_TEAMS[self.team] enemies = [thing for thing in things.values() if thing.team == enemy_team] enemy_ancient = [e for e in enemies if e.name == 'ancient'][0] enemy_tower = [e for e in enemies if e.name == 'tower'] if enemy_tower: enemy_tower = enemy_tower[0] enemy_hero = [e for e in enemies if e.__class__.__name__ == "Hero"] if enemy_hero: enemy_hero = enemy_hero[0] closest_enemy = closest(self, enemies) closest_enemy_distance = distance(self, closest_enemy) friends = [thing for thing in things.values() if thing.team == self.team and thing != self] friendly_ancient = [e for e in friends if e.name == 'ancient'][0] back_friends = sort_by_distance(self, friends)[2:] closest_friend = closest(self, friends) closest_friend_distance = distance(self, closest_friend) # I'm offside if there are not at least 2 friendlies in front of me offside = closest(enemy_ancient, back_friends + [self]) == self # There are enemy units behind me enemy_offside = closest(friendly_ancient, enemies + [self]) != self # log("offside: "+ str(offside)) # log("friend: %s, enemy: %s" % (str(closest_friend), str(closest_enemy))) # if I can stun the other hero, that's highest priority if closest_enemy and closest_enemy == enemy_hero\ and closest_enemy_distance <= settings.STUN_DISTANCE and self.can('stun', t): # try to stun him log('stun !!!') return 'stun', closest_enemy.position # move to get conver if I'm low on energy or there's an enemy behind me if (offside and self.life < 200):# or enemy_offside: moves = sort_by_distance(friendly_ancient, valid_positions(self, things)) return 'move', moves[0] if self.life < (self.max_life - settings.HEAL_BASE_HEALING[1]) and self.can('heal', t)\ and (closest_friend and closest_friend_distance <= settings.HEAL_DISTANCE): log("heal") return 'heal', self.position else: if closest_enemy: # there is an enemy # if closest_enemy_distance <= settings.FIREBALL_DISTANCE and self.can('fireball', t) and closest_enemy_distance > settings.FIREBALL_RADIUS and closest_friend_distance > (settings.FIREBALL_DISTANCE + settings.FIREBALL_RADIUS): if self.can('fireball', t) and closest_enemy_distance < settings.FIREBALL_DISTANCE +settings.FIREBALL_RADIUS\ and closest_enemy_distance > settings.FIREBALL_RADIUS\ and distance(closest_friend, closest_enemy) > settings.FIREBALL_RADIUS: # else try to fireball him, but only if I'm not in range log("fireball !!!") return 'fireball', closest_enemy.position elif closest_enemy_distance <= settings.HERO_ATTACK_DISTANCE: # else try to attack him log("attack") return 'attack', closest_enemy.position else: if enemy_tower: if distance(self,enemy_tower) < 5: log("halt") return moves = sort_by_distance(enemy_ancient, valid_positions(self, things)) return 'move', moves[0]