Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. game = None
  2. _planets = {}
  3. SHIPS_TO_NEW_CONCOURED = 10
  4.  
  5. def do_turn(pw):
  6. global game
  7. game = pw
  8.  
  9. if len(game.my_planets()) == 0:
  10. return
  11.  
  12. for planet in game.my_planets():
  13. _planets[planet.planet_id()] = planet.num_ships()
  14.  
  15. # loop through every planet
  16. for planet in game.my_planets():
  17. # Wierd things happen here...
  18. for i in range(3):
  19. if len(game.neutral_planets()) > 0:
  20. if not enemy_planet_will_be_conquered(get_closest(planet, game.neutral_planets())):
  21. if issue_attack(planet, get_closest(planet, game.neutral_planets())):
  22. pass
  23.  
  24. if len(game.enemy_planets()) > 0:
  25. if not enemy_planet_will_be_conquered(get_closest(planet, game.enemy_planets())):
  26. if issue_attack(planet, get_closest(planet, game.enemy_planets())):
  27. continue
  28.  
  29. def enemy_planet_will_be_conquered(ePlanet):
  30. global game
  31. ships_sent = 0
  32. max_turns = 0
  33. for flee in game.my_fleets():
  34. if flee.destination_planet == ePlanet:
  35. ships_sent += flee.num_ships()
  36. if flee.turns_remaining() > max_turns:
  37. max_turns = flee.turns_remaining()
  38. if ships_sent > ships_will_have(max_turns, ePlanet):
  39. return True
  40. return False
  41.  
  42.  
  43. def my_planet_will_be_conquered(planet):
  44. global game
  45. ships_sent = 0
  46. max_turns = 0
  47. for flee in game.enemy_fleets():
  48. if flee.destination_planet == planet:
  49. ships_sent += flee.num_ships()
  50. if flee.turns_remaining() > max_turns:
  51. max_turns = flee.turns_remaining()
  52. if ships_sent > ships_will_have(max_turns, planet):
  53. return True
  54. return False
  55.  
  56. def ships_will_have(turns, planet):
  57. return planet.num_ships() + (planet.growth_rate() * turns)
  58.  
  59. def issue_attack(planet, enemy, num_of_ships=None):
  60. global _planet, game
  61. if num_of_ships == None:
  62. num_of_ships = enemy.num_ships() + SHIPS_TO_NEW_CONCOURED
  63. if _planets[planet.planet_id()] > num_of_ships:
  64. game.issue_order(planet, enemy, num_of_ships)
  65. _planets[planet.planet_id()] -= num_of_ships
  66. return True
  67. return False
  68.  
  69. def get_closest(planet, planets):
  70. global game
  71. return min(planets, key=(lambda x: game.distance(planet, x)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement