Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. def do_turn(pw):
  2. if len(pw.my_fleets()) >= 1:
  3. return
  4. if len(pw.my_planets()) == 0:
  5. return
  6. else:
  7. my_planet_list = pw.my_planets()
  8. my_planet_list.sort(key=myFunc, reverse=True)
  9. for i in range(0, len(my_planet_list)):
  10. dest = get_closest_neutral_planet(pw, my_planet_list[i])
  11. if my_planet_list[i].num_ships() > dest.num_ships():
  12. pw.issue_order(my_planet_list[i], dest, dest.num_ships() + 1)
  13.  
  14. def myFunc(planet):
  15. return planet.num_ships()
  16.  
  17. def get_closest_neutral_planet(pw, source):
  18. try:
  19. min_dist = 1000
  20. dest = pw.not_my_planets()[0]
  21. cost = 0
  22. for p in pw.not_my_planets():
  23. if min_dist > pw.distance(source, p):
  24. min_dist = pw.distance(source, p)
  25. dest = p
  26. except:
  27. dest = 0
  28. return dest
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement