Advertisement
Guest User

Skillz 2019 15.1

a guest
Jan 16th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.43 KB | None | 0 0
  1. from elf_kingdom import *
  2. import random
  3.  
  4.  
  5. def do_turn(game):
  6.     handle_elves(game)
  7.     handle_portals(game)
  8.  
  9. def handle_elves(game):
  10.     enemy_castle = game.get_enemy_castle()
  11.     my_castle = game.get_my_castle()
  12.    
  13.     for elf in game.get_my_living_elves():
  14.         elf_state = ""
  15.         closest_portal = -1
  16.        
  17.         for i, portal in enumerate(game.get_enemy_portals()):
  18.             if elf.in_attack_range(portal):
  19.                 elf.attack(portal)
  20.                 elf_state = "attack"
  21.             elif elf.in_range(portal, 2000):
  22.                 if closest_portal > -1 and closest_portal < len(game.get_enemy_portals()):
  23.                     if elf.distance(game.get_enemy_portals()[i]) < elf.distance(game.get_enemy_portals()[closest_portal]):
  24.                         closest_portal = i
  25.                 else:
  26.                     closest_portal = i
  27.         if closest_portal > -1 and closest_portal < len(game.get_enemy_portals()) and elf_state == "":
  28.             elf.move_to(game.get_enemy_portals()[closest_portal])
  29.             elf_state = "move"
  30.         for entity in game.get_enemy_living_elves() + game.get_enemy_lava_giants():
  31.             if entity.in_range(my_castle, 1000) and elf_state == "":
  32.                 if elf.in_attack_range(entity):
  33.                     elf.attack(entity)
  34.                     elf_state = "attack"
  35.                     break
  36.                 else:
  37.                     elf.move_to(entity)
  38.                     elf_state = "move"
  39.                     break
  40.         if elf_state == "":
  41.             if elf.can_build_portal():
  42.                 elf.build_portal()
  43.                 elf_state = "build"
  44.             elif elf.in_attack_range(enemy_castle):
  45.                 elf.attack(enemy_castle)
  46.                 elf_state = "attack"
  47.             else:
  48.                 # for entity in game.get_enemy_ice_trolls() + game.get_enemy_living_elves():
  49.                 #     if elf_state == "":
  50.                 #         if elf.in_range(entity, 500):
  51.                 #             if not entity.in_range(my_castle, entity.attack_range + 50):
  52.                 #                 new_loc = elf.get_location().towards(entity, -1000)
  53.                 #                 if new_loc.in_map():
  54.                 #                     elf.move_to(new_loc)
  55.                 #                     elf_state = "move"
  56.                 #                 else:
  57.                 #                     if elf.in_attack_range(entity):
  58.                 #                         elf.attack(entity)
  59.                 #                         elf_state = "attack"
  60.                 #                     else:
  61.                 #                         elf.move_to(entity)
  62.                 #                         elf_state = "move"
  63.                 #    else:
  64.                 #        break
  65.                 if elf_state == "":
  66.                     elf.move_to(enemy_castle)
  67.                     elf_state = "move"
  68.            
  69.             for portal in game.get_my_portals():
  70.                 if elf_state == "":
  71.                     if portal.current_health <= game.portal_max_health * 0.7:
  72.                         if portal.in_range(my_castle, 2000) and elf.in_range(portal, 2000) and elf.can_build_portal():
  73.                             elf.build_portal()
  74.                         elif elf.in_range(portal, 500) and elf.can_build_portal():
  75.                             elf.build_portal()
  76.                            
  77. def handle_portals(game):
  78.     portals = game.get_my_portals()
  79.     my_castle = game.get_my_castle()
  80.    
  81.     if len(portals) > 1:
  82.         for portal in portals:
  83.             nearby_mobs = 0
  84.            
  85.             for entity in game.get_enemy_creatures() + game.get_enemy_living_elves():
  86.                 if portal.in_range(entity, 3000):
  87.                     nearby_mobs += 1
  88.            
  89.             to_spawn = random.randint(1, int((nearby_mobs ** -1) * 10)) if nearby_mobs > 0 else random.randint(1, 12)
  90.                    
  91.             if to_spawn == 1:
  92.                 if nearby_mobs >= 1 and portal.can_summon_ice_troll():
  93.                     portal.summon_ice_troll()
  94.                     print 'portal ', portal, ' summons an ice troll'
  95.                 elif to_spawn == 1 and (not portal.in_range(my_castle, 1500) or len(game.get_enemy_lava_giants()) > len(game.get_my_lava_giants())) and portal.can_summon_lava_giant():
  96.                     portal.summon_lava_giant()
  97.                     print 'portal ', portal, ' summons a lava giant'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement