Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- game = None
- _planets = {}
- SHIPS_TO_NEW_CONCOURED = 10
- def do_turn(pw):
- global game
- game = pw
- if len(game.my_planets()) == 0:
- return
- for planet in game.my_planets():
- _planets[planet.planet_id()] = planet.num_ships()
- # loop through every planet
- for planet in game.my_planets():
- # Wierd things happen here...
- for i in range(3):
- if len(game.neutral_planets()) > 0:
- if not enemy_planet_will_be_conquered(get_closest(planet, game.neutral_planets())):
- if issue_attack(planet, get_closest(planet, game.neutral_planets())):
- pass
- if len(game.enemy_planets()) > 0:
- if not enemy_planet_will_be_conquered(get_closest(planet, game.enemy_planets())):
- if issue_attack(planet, get_closest(planet, game.enemy_planets())):
- continue
- def enemy_planet_will_be_conquered(ePlanet):
- global game
- ships_sent = 0
- max_turns = 0
- for flee in game.my_fleets():
- if flee.destination_planet == ePlanet:
- ships_sent += flee.num_ships()
- if flee.turns_remaining() > max_turns:
- max_turns = flee.turns_remaining()
- if ships_sent > ships_will_have(max_turns, ePlanet):
- return True
- return False
- def my_planet_will_be_conquered(planet):
- global game
- ships_sent = 0
- max_turns = 0
- for flee in game.enemy_fleets():
- if flee.destination_planet == planet:
- ships_sent += flee.num_ships()
- if flee.turns_remaining() > max_turns:
- max_turns = flee.turns_remaining()
- if ships_sent > ships_will_have(max_turns, planet):
- return True
- return False
- def ships_will_have(turns, planet):
- return planet.num_ships() + (planet.growth_rate() * turns)
- def issue_attack(planet, enemy, num_of_ships=None):
- global _planet, game
- if num_of_ships == None:
- num_of_ships = enemy.num_ships() + SHIPS_TO_NEW_CONCOURED
- if _planets[planet.planet_id()] > num_of_ships:
- game.issue_order(planet, enemy, num_of_ships)
- _planets[planet.planet_id()] -= num_of_ships
- return True
- return False
- def get_closest(planet, planets):
- global game
- return min(planets, key=(lambda x: game.distance(planet, x)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement