Advertisement
kiubia

code

Jan 18th, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. import sys
  2. import math
  3. import time
  4.  
  5. class Site:
  6. def __init__(self, row_input):
  7. self.site_id, self.x, self.y, self.radius = map(int, row_input.split())
  8.  
  9. def update(self, row_input):
  10. self.site_id, self.ignore_1, self.ignore_2, self.structure_type, self.owner, self.param_1, self.param_2 = map(int, row_input.split())
  11.  
  12. class Unit:
  13. me = None
  14. enemy = None
  15. def __init__(self, row_input):
  16. self.x, self.y, self.owner, self.unit_type, self.health = map(int, row_input.split())
  17. if self.owner == 0 and self.unit_type == -1:
  18. Unit.me = self
  19. if self.owner == 1 and self.unit_type == -1:
  20. Unit.enemy = self
  21.  
  22. def dist(self, other):
  23. return math.sqrt((other.x - self.x) ** 2 + (other.y - self.y) ** 2)
  24.  
  25. num_sites = int(input())
  26. sites = [Site(input()) for i in range(num_sites)]
  27.  
  28. while True:
  29. gold, touched_site = map(int,input().split())
  30. for s in sites: s.update(input())
  31. num_units = int(input())
  32. units = [Unit(input()) for _ in range(num_units)]
  33. empty_sites = filter(lambda s: s.structure_type == -1,sites)
  34. dists = sorted(empty_sites,key= lambda s: dist(Unit.me,s))
  35. my_sites = list(filter(lambda s: s.owner == 0,sites))
  36. to_enemy_dists = sorted(my_sites,key= lambda s: dist(Unit.enemy,s))
  37. no_knights = len(list(filter(lambda s: s.param_2 == 0, my_sites)))
  38. no_archers = len(list(filter(lambda s: s.param_2 == 1, my_sites)))
  39. if no_knights < 2:
  40. if no_archers < 2:
  41. print("BUILD " + str(dists[0].site_id) + " BARRACKS-ARCHER")
  42. else:
  43. print("BUILD " + str(dists[0].site_id) + " BARRACKS-KNIGHT")
  44. else:
  45. print("WAIT")
  46. no_archer_units = len(list(filter(lambda u: u.owner == 0 and u.unit_type == 1, units)))
  47. st=""
  48. for s in to_enemy_dists:
  49. if no_archer_units < 2 :
  50. if gold >= 100 and s.param_2 == 1:
  51. st += " " + str(s.site_id)
  52. gold -= 100
  53. else:
  54. if gold >= 80 and s.param_2 == 0:
  55. st += " " + str(s.site_id)
  56. gold -= 80
  57. print("TRAIN" + st)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement