Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from elf_kingdom import *
- import random
- def do_turn(game):
- handle_elves(game)
- handle_portals(game)
- def handle_elves(game):
- enemy_castle = game.get_enemy_castle()
- my_castle = game.get_my_castle()
- for elf in game.get_my_living_elves():
- elf_state = ""
- closest_portal = -1
- for i, portal in enumerate(game.get_enemy_portals()):
- if elf.in_attack_range(portal):
- elf.attack(portal)
- elf_state = "attack"
- elif elf.in_range(portal, 2000):
- if closest_portal > -1 and closest_portal < len(game.get_enemy_portals()):
- if elf.distance(game.get_enemy_portals()[i]) < elf.distance(game.get_enemy_portals()[closest_portal]):
- closest_portal = i
- else:
- closest_portal = i
- if closest_portal > -1 and closest_portal < len(game.get_enemy_portals()) and elf_state == "":
- elf.move_to(game.get_enemy_portals()[closest_portal])
- elf_state = "move"
- for entity in game.get_enemy_living_elves() + game.get_enemy_lava_giants():
- if entity.in_range(my_castle, 1000) and elf_state == "":
- if elf.in_attack_range(entity):
- elf.attack(entity)
- elf_state = "attack"
- break
- else:
- elf.move_to(entity)
- elf_state = "move"
- break
- if elf_state == "":
- if elf.can_build_portal():
- elf.build_portal()
- elf_state = "build"
- elif elf.in_attack_range(enemy_castle):
- elf.attack(enemy_castle)
- elf_state = "attack"
- else:
- # for entity in game.get_enemy_ice_trolls() + game.get_enemy_living_elves():
- # if elf_state == "":
- # if elf.in_range(entity, 500):
- # if not entity.in_range(my_castle, entity.attack_range + 50):
- # new_loc = elf.get_location().towards(entity, -1000)
- # if new_loc.in_map():
- # elf.move_to(new_loc)
- # elf_state = "move"
- # else:
- # if elf.in_attack_range(entity):
- # elf.attack(entity)
- # elf_state = "attack"
- # else:
- # elf.move_to(entity)
- # elf_state = "move"
- # else:
- # break
- if elf_state == "":
- elf.move_to(enemy_castle)
- elf_state = "move"
- for portal in game.get_my_portals():
- if elf_state == "":
- if portal.current_health <= game.portal_max_health * 0.7:
- if portal.in_range(my_castle, 2000) and elf.in_range(portal, 2000) and elf.can_build_portal():
- elf.build_portal()
- elif elf.in_range(portal, 500) and elf.can_build_portal():
- elf.build_portal()
- def handle_portals(game):
- portals = game.get_my_portals()
- my_castle = game.get_my_castle()
- if len(portals) > 1:
- for portal in portals:
- nearby_mobs = 0
- for entity in game.get_enemy_creatures() + game.get_enemy_living_elves():
- if portal.in_range(entity, 3000):
- nearby_mobs += 1
- to_spawn = random.randint(1, int((nearby_mobs ** -1) * 10)) if nearby_mobs > 0 else random.randint(1, 12)
- if to_spawn == 1:
- if nearby_mobs >= 1 and portal.can_summon_ice_troll():
- portal.summon_ice_troll()
- print 'portal ', portal, ' summons an ice troll'
- 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():
- portal.summon_lava_giant()
- print 'portal ', portal, ' summons a lava giant'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement