Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.19 KB | None | 0 0
  1. def find_length(pw, planet_to_find):
  2.     length_sum = 0
  3.     for planet in pw.my_planets():
  4.         length_sum += ((planet_to_find.x() - planet.x()) ** 2 + (planet_to_find.y() - planet.y()) ** 2) ** 0.5
  5.  
  6.     return length_sum / len(pw.my_planets())
  7.  
  8.  
  9. class PlanetValues:
  10.     def __init__(self, index, value):
  11.         self.index = index
  12.         self.value = value
  13.  
  14.  
  15. def find_who_to_conquer(pw):
  16.     lengths = []
  17.     growths = []
  18.     ship_amount = []
  19.     for i, planet in enumerate(pw.not_my_planets()):
  20.         lengths.append(PlanetValues(i, find_length(pw, planet)))
  21.         growths.append(PlanetValues(i, planet.growth_rate()))
  22.         ship_amount.append(PlanetValues(i, planet.num_ships()))
  23.     lengths.sort(key=lambda x: x.value)
  24.     growths.sort(key=lambda x: x.value, reverse=True)
  25.     ship_amount.sort(key=lambda x: x.value)
  26.  
  27.     planet_indexes = {}
  28.     for i, planet in enumerate(lengths):
  29.         planet_indexes[planet.index] = i
  30.  
  31.     for i, planet in enumerate(growths):
  32.         planet_indexes[planet.index] += i
  33.  
  34.     for i, planet in enumerate(ship_amount):
  35.         planet_indexes[planet.index] += i
  36.  
  37.     return pw.not_my_planets()[min(planet_indexes, key=planet_indexes.get)]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement