Created
August 3, 2022 09:04
-
-
Save Plutoberth/c053fb1a433d3170a5f8dfb5de0df57c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def do_turn(pw): | |
# (1) If we currently have a fleet in flight, just do nothing. | |
if len(pw.MyFleets()) >= 1: | |
return | |
# (2) Find my strongest planet. | |
source = -1 | |
source_score = -999999.0 | |
source_num_ships = 0 | |
my_planets = pw.MyPlanets() | |
for p in my_planets: | |
score = float(p.NumShips()) | |
if score > source_score: | |
source_score = score | |
source = p.PlanetID() | |
source_num_ships = p.NumShips() | |
# (3) Find the weakest enemy or neutral planet. | |
dest = -1 | |
dest_score = -999999.0 | |
not_my_planets = pw.NotMyPlanets() | |
for p in not_my_planets: | |
score = 1.0 / (1 + p.NumShips()) | |
if score > dest_score: | |
dest_score = score | |
dest = p.PlanetID() | |
# (4) Send half the ships from my strongest planet to the weakest | |
# planet that I do not own. | |
if source >= 0 and dest >= 0: | |
num_ships = source_num_ships / 2 | |
pw.IssueOrder(source, dest, num_ships) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment