def still_damage(self, things, t, defaultpos=None): # Estimate damage that I will get by standing still enemy_team = settings.ENEMY_TEAMS[self.team] enemies = [thing for thing in things.values() if thing.team == enemy_team] friends = [thing for thing in things.values() if thing.team == self.team] position = defaultpos or self.position result = 0 for e in enemies: if e.disabled_until > t or not e.alive: # filter stunned stuff pass elif e.name == 'ancient': pass elif e.name == 'tower': if distance(position, e.position) <= settings.TOWER_ATTACK_DISTANCE and closest(e, friends) == self: result += sum(settings.TOWER_ATTACK_BASE_DAMAGE) / 2 elif e.name == 'creep': if distance(position, e.position) <= settings.CREEP_ATTACK_DISTANCE and closest(e, friends) == self: result += sum(settings.CREEP_ATTACK_BASE_DAMAGE) / 2 else: # assume hero multiplier = (1 + settings.HERO_ATTACK_LEVEL_MULTIPLIER * e.level) if e.can('fireball', t) and distance(position, e.position) <= settings.FIREBALL_RADIUS+1: result += sum(settings.FIREBALL_BASE_DAMAGE) / 2 * multiplier elif e.can('stun', t) and distance(position, e.position) <= settings.STUN_DISTANCE: result += settings.STUN_DURATION*sum(settings.HERO_ATTACK_BASE_DAMAGE) / 2 * multiplier elif distance(e.position, position) <= settings.HERO_ATTACK_DISTANCE: result += sum(settings.HERO_ATTACK_BASE_DAMAGE) / 2 * multiplier return result
def safe_fireball(hero, enemy, closest_friend, t): enemy_distance = distance(hero, enemy) if hero.can('fireball', t) and enemy_distance <= settings.FIREBALL_DISTANCE\ and enemy_distance > settings.FIREBALL_RADIUS\ and distance(closest_friend, enemy) > settings.FIREBALL_RADIUS: return True else: return False
def gbytz_hero_logic(self, things, t): nonlocal ally_base, ally_tower, enemy_base, enemy_tower, enemy_hero if not (ally_base and ally_tower and enemy_base and enemy_tower): ally_base, ally_tower, enemy_base, enemy_tower = get_buildings(things, self.team) enemy_hero = get_enemy_hero(things, self.team) ally_creeps, enemy_creeps = get_creeps(things, self.team) a_front, a_back, e_front, e_back = get_lines(self, ally_creeps, enemy_creeps) heal_power = calculate_power(self, settings.HEAL_BASE_HEALING, settings.HEAL_LEVEL_MULTIPLIER) fireball_power = calculate_power(self, settings.FIREBALL_BASE_DAMAGE, settings.FIREBALL_LEVEL_MULTIPLIER) enemies = sort_by_threat(get_enemies_at_distance(self, things, 7)) if self.life <= self.max_life - heal_power and self.can('heal', t): delta = (0, 0) return 'heal', (self.position[0] + delta[0], self.position[1] + delta[1]) skirmish_points = eval_skirmish(self, ally_tower, ally_creeps, enemy_hero, enemy_tower, enemy_creeps) if skirmish_points <= 0 : if ally_tower.life > 0 and len(a_back) > 0: if distance(self, ally_tower) < distance(self, closest(ally_base, a_back)): target = ally_tower else: target = closest(ally_base, a_back) elif ally_tower.life > 0: target = ally_tower elif len(a_back) > 0: target = closest(ally_base, a_back) else: target = ally_base action = move_to_target(self, target, things) elif skirmish_points > 0: if len(enemies) > 0: action = attack_enemies(self, enemies, t, things) else: if len(e_front) > 0: target = closest(ally_base, e_front) elif enemy_tower.life > 0: target = enemy_tower else: target = enemy_base action = move_to_target(self, target, things) return action
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 eval_skirmish(hero, ally_tower, ally_creeps, enemy_hero, enemy_tower, enemy_creeps): a_front, a_back, e_front, e_back = get_lines(hero, ally_creeps, enemy_creeps) total_points = 0 total_points += len(a_front) if enemy_hero is not None and distance(hero, enemy_hero) <= 7: total_points += hero.level - enemy_hero.level total_points -= len(e_front) if ally_tower is not None and ally_tower.life > 0 and distance(hero, ally_tower) <= 2: total_points += 5 if enemy_tower is not None and enemy_tower.life > 0 and distance(hero, enemy_tower) <= 3: total_points -= 5 return total_points
def action_with_distance_check(thing, world, target_position): if distance(thing, target_position) > action_distance: event = 'too far away' else: event = f(thing, world, target_position) return event
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 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) if distance(self, closest_enemy) <= settings.TOWER_ATTACK_DISTANCE: return 'attack', closest_enemy.position else: return None
def get_lines(hero, ally_creeps, enemy_creeps): a_front = [] a_back = [] for ally in ally_creeps: if distance(ally, hero) > 5: a_back.append(ally) else: a_front.append(ally) e_front = [] e_back = [] for enemy in enemy_creeps: if distance(enemy, hero) > 8: e_back.append(enemy) else: e_front.append(enemy) return a_front, a_back, e_front, e_back
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 update_experience(self): for thing in list(self.world.things.values()): if not thing.alive: for hero in self.heroes: if hero.alive and hero.team != thing.team and distance(hero, thing) < settings.XP_DISTANCE: if isinstance(thing, Creep): hero.xp += settings.XP_CREEP_DEAD elif isinstance(thing, Hero): hero.xp += settings.XP_HERO_DEAD elif isinstance(thing, Tower): hero.xp += settings.XP_TOWER_DEAD
def update_experience(self): for thing in list(self.world.things.values()): if not thing.alive: for hero in self.heroes: if hero.alive and hero.team != thing.team and distance( hero, thing) < settings.XP_DISTANCE: if isinstance(thing, Creep): hero.xp += settings.XP_CREEP_DEAD elif isinstance(thing, Hero): hero.xp += settings.XP_HERO_DEAD elif isinstance(thing, Tower): hero.xp += settings.XP_TOWER_DEAD
def still_damage(self, things, t, defaultpos=None): # Estimate damage that I will get by standing still enemy_team = settings.ENEMY_TEAMS[self.team] enemies = [thing for thing in things.values() if thing.team == enemy_team] friends = [thing for thing in things.values() if thing.team == self.team] position = defaultpos or self.position result = 0 for e in enemies: if e.disabled_until > t or not e.alive: # filter stunned stuff pass elif e.name == 'ancient': pass elif e.name == 'tower': if distance( position, e.position) <= settings.TOWER_ATTACK_DISTANCE and closest( e, friends) == self: result += sum(settings.TOWER_ATTACK_BASE_DAMAGE) / 2 elif e.name == 'creep': if distance( position, e.position) <= settings.CREEP_ATTACK_DISTANCE and closest( e, friends) == self: result += sum(settings.CREEP_ATTACK_BASE_DAMAGE) / 2 else: # assume hero multiplier = (1 + settings.HERO_ATTACK_LEVEL_MULTIPLIER * e.level) if e.can('fireball', t) and distance( position, e.position) <= settings.FIREBALL_RADIUS + 1: result += sum(settings.FIREBALL_BASE_DAMAGE) / 2 * multiplier elif e.can('stun', t) and distance( position, e.position) <= settings.STUN_DISTANCE: result += settings.STUN_DURATION * sum( settings.HERO_ATTACK_BASE_DAMAGE) / 2 * multiplier elif distance(e.position, position) <= settings.HERO_ATTACK_DISTANCE: result += sum( settings.HERO_ATTACK_BASE_DAMAGE) / 2 * multiplier 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 heal(thing, world, target_position): event_bits = [] for position, target in world.things.items(): if distance(target_position, target) <= settings.HEAL_RADIUS: # heal avoiding health overflow heal = calculate_damage(thing, settings.HEAL_BASE_HEALING, settings.HEAL_LEVEL_MULTIPLIER) target.life = min(target.max_life, target.life + heal) event_bits.append('healed {} by {}'.format(target.name, heal)) update_last_use(thing, world, 'heal') return ', '.join(event_bits)
def update_experience(self): """Add the experience gained for being close to enemy deads.""" for thing in list(self.world.things.values()): if not thing.alive: for hero in self.heroes: if hero.alive and hero.team != thing.team and distance(hero, thing) < settings.XP_DISTANCE: xp_gain = 0 if isinstance(thing, Creep): xp_gain = settings.XP_CREEP_DEAD elif isinstance(thing, Hero): xp_gain = settings.XP_HERO_DEAD elif isinstance(thing, Tower): xp_gain = settings.XP_TOWER_DEAD hero.xp += xp_gain self.event(hero, 'gained {} xp'.format(xp_gain))
def fireball(thing, world, target_position): event_bits = [] for position, target in world.things.items(): if distance(target_position, target) <= settings.FIREBALL_RADIUS: damage = calculate_damage(thing, settings.FIREBALL_BASE_DAMAGE, settings.FIREBALL_LEVEL_MULTIPLIER) target.life -= damage event_bits.append('damaged {} with fire by {}'.format(target.name, damage)) update_last_use(thing, world, 'fireball') return ', '.join(event_bits)
def update_experience(self): """Add the experience gained for being close to enemy deads.""" for thing in list(self.world.things.values()): if not thing.alive: for hero in self.heroes: if (hero.alive and hero.team != thing.team and distance(hero, thing) < settings.XP_DISTANCE): xp_gain = 0 if isinstance(thing, Creep): xp_gain = settings.XP_CREEP_DEAD elif isinstance(thing, Hero): xp_gain = settings.XP_HERO_DEAD elif isinstance(thing, Tower): xp_gain = settings.XP_TOWER_DEAD hero.xp += xp_gain self.event(hero, 'gained {} xp'.format(xp_gain))
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 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
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 in_radius(position, things, radius): list_thing = list() for thing in things: if distance(position, thing) <= radius: list_thing.append(thing) return list_thing
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 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 get_enemies_at_distance(hero, things, dist): enemies = [] for thing in things.values(): if thing.team not in (hero.team, settings.TEAM_NEUTRAL) and distance(hero, thing) < dist and thing.life > 0: enemies.append(thing) return enemies
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 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 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 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 attack_enemies(hero, enemies, t, things): can_fireball = hero.can('fireball', t) can_stun = hero.can('stun', t) main_threat = enemies[0] print(main_threat) dist_to_threat = distance(main_threat, hero) action_str = None target_position = main_threat.position if isinstance(main_threat, Tower): if dist_to_threat == 1: action_str = 'attack' elif dist_to_threat <= settings.STUN_DISTANCE: if can_stun: action_str = 'stun' else: return move_to_target(hero, main_threat, things) elif dist_to_threat <= settings.FIREBALL_DISTANCE and dist_to_threat > 2: if can_fireball: action_str = 'fireball' else: return move_to_target(hero, main_threat, things) else: # Pensar como pegarle con el AOE pass elif isinstance(main_threat, Hero): if dist_to_threat == 1: if hero.life >= main_threat.life: action_str = 'attack' else: action_str = 'move' target_position = (hero.position[0] - 1, hero.position[1] - 1) elif dist_to_threat <= settings.STUN_DISTANCE: if can_stun: action_str = 'stun' elif dist_to_threat <= settings.FIREBALL_DISTANCE and dist_to_threat > 2: if can_fireball: action_str = 'fireball' else: # Pensar como pegarle con el AOE pass elif isinstance(main_threat, Creep): if dist_to_threat == 1: action_str = 'attack' elif can_fireball: if dist_to_threat <= settings.FIREBALL_DISTANCE and dist_to_threat > 2: action_str = 'fireball' else: return move_to_target(hero, main_threat, things) else: if dist_to_threat == 1: action_str = 'attack' elif can_fireball: if dist_to_threat <= settings.FIREBALL_DISTANCE and dist_to_threat > 2: action_str = 'fireball' else: return move_to_target(hero, main_threat, things) if action_str is None: action = None else: action = action_str, target_position return action
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]