Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def find_length(pw, planet_to_find):
- length_sum = 0
- for planet in pw.my_planets():
- length_sum += ((planet_to_find.x() - planet.x()) ** 2 + (planet_to_find.y() - planet.y()) ** 2) ** 0.5
- return length_sum / len(pw.my_planets())
- class PlanetValues:
- def __init__(self, index, value):
- self.index = index
- self.value = value
- def find_who_to_conquer(pw):
- lengths = []
- growths = []
- ship_amount = []
- for i, planet in enumerate(pw.not_my_planets()):
- lengths.append(PlanetValues(i, find_length(pw, planet)))
- growths.append(PlanetValues(i, planet.growth_rate()))
- ship_amount.append(PlanetValues(i, planet.num_ships()))
- lengths.sort(key=lambda x: x.value)
- growths.sort(key=lambda x: x.value, reverse=True)
- ship_amount.sort(key=lambda x: x.value)
- planet_indexes = {}
- for i, planet in enumerate(lengths):
- planet_indexes[planet.index] = i
- for i, planet in enumerate(growths):
- planet_indexes[planet.index] += i
- for i, planet in enumerate(ship_amount):
- planet_indexes[planet.index] += i
- return pw.not_my_planets()[min(planet_indexes, key=planet_indexes.get)]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement