Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. import sys
  2. import os
  3. import importlib
  4.  
  5. from PlanetWars import PlanetWars
  6.  
  7. def do_turn(pw):
  8. #if you lose end
  9. if len(pw.my_planets()) == 0:
  10. return
  11.  
  12. if len(pw.my_fleets()) >= 1:
  13. try:
  14. #find the planet with the highest number of ships
  15. largest_ships = pw.my_planets()[0]
  16. for planet in pw.my_planets():
  17. if planet.num_ships() > largest_ships.num_ships():
  18. #replace
  19. largest_ships = planet
  20. source = largest_ships
  21.  
  22. p = pw.enemy_planets()[0]
  23. for planet in pw.enemy_planets():
  24. if pw.distance(source, planet) < pw.distance(source, p):
  25. p = planet
  26.  
  27. dest = p
  28.  
  29. num_ships = source.num_ships() / 2
  30. if(source.num_ships() > 200):
  31. pw.issue_order(source, dest, num_ships)
  32. except:
  33. i = 0
  34.  
  35. if pw.my_planets()[0].num_ships() > 250:
  36. #team has more than 150 ships start to attack the enemy
  37.  
  38. #if you are not attacking attack
  39. if len(pw.my_fleets()) == 0:
  40. #find a planet to attack
  41. smallest_planet = pw.enemy_planets()[0]
  42. for planet in pw.enemy_planets():
  43. if planet.num_ships() < smallest_planet.num_ships():
  44. #replace
  45. smallest_planet = planet
  46.  
  47. dest = smallest_planet
  48. source = pw.my_planets()[0]
  49.  
  50. num_ships = source.num_ships() / 2
  51.  
  52. pw.issue_order(source, dest, num_ships)
  53. else:
  54. #find nearest planet
  55. try:
  56. try:
  57. nearest_planet = pw.neutral_planets()[0]
  58. for planet in pw.neutral_planets():
  59. if planet.x() > nearest_planet.x():
  60. #replace
  61. nearest_planet = planet
  62. except:
  63. pw.debug("no neutral")
  64. for planet in pw.enemy_planets():
  65. if planet.x() > nearest_planet.x():
  66. #replace
  67. nearest_planet = planet
  68. dest = nearest_planet
  69.  
  70. #find the nearest planet with enugh ships
  71. nearest_p_home = pw.my_planets()[0]
  72. for planet in pw.my_planets():
  73. if (pw.distance(planet, dest) < pw.distance(nearest_p_home, dest)) and (dest.num_ships() + 30 < planet.num_ships()):
  74. nearest_p_home = planet
  75. source = nearest_p_home
  76.  
  77. num_ships = dest.num_ships() + 30
  78. if num_ships > source.num_ships():
  79. pw.debug("sentLow")
  80. num_ships = source.num_ships()
  81.  
  82.  
  83. pw.issue_order(source, dest, num_ships)
  84. except:
  85. i = 0
  86. pw.debug("exception")
  87.  
  88. def find_smallest_distance_between_two_star_lists(home_stars, neutral_stars):
  89. nearest = pw.distance(home_stars[0], neutral_stars[0])
  90.  
  91. for homeStar in home_stars:
  92. for neutralStar in neutral_stars:
  93. if pw.distance(homeStar, neutralStar) < nearest:
  94. hs=homeStar
  95. ns=neutralStar
  96. nearest=pw.distance(homeStar, neutralStar)
  97.  
  98. return (hs, ns)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement