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 predict_moves(self, things, t): result = [] for p in possible_moves(self, things)+[self.position]: received = still_damage(self, things, t, self.position)/2 + still_damage(self, things, t, p)/2 will_die = 0 if received >= self.life: received = self.life will_die = 1 result.append(mkaction('move', p, hero_kills=-will_die, damage=-received)) return result
def predict_moves(self, things, t): result = [] for p in possible_moves(self, things) + [self.position]: received = still_damage(self, things, t, self.position ) / 2 + still_damage(self, things, t, p) / 2 will_die = 0 if received >= self.life: received = self.life will_die = 1 result.append( mkaction('move', p, hero_kills=-will_die, damage=-received)) return result
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 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 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 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 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