Skip to content

Instantly share code, notes, and snippets.

@Gavriel770U
Last active August 8, 2024 20:56
Show Gist options
  • Save Gavriel770U/f0e1d910fc28c853fa799df812307be2 to your computer and use it in GitHub Desktop.
Save Gavriel770U/f0e1d910fc28c853fa799df812307be2 to your computer and use it in GitHub Desktop.
bot.py
def score(src, planet, pw):
scoring = planet.growth_rate() * 10 - planet.num_ships()
#distance
for my_planet in pw.my_planets():
total_distance = pw.distance(my_planet, planet)
scoring -= total_distance
#fleets for planet
num_of_ships_to_planet = 0
num_of_ships_from_planet = 0
for enemy_fleet in pw.enemy_fleets():
if enemy_fleet.destination_planet() == planet:
num_of_ships_to_planet += enemy_fleet.num_ships()
elif enemy_fleet.source_planet() == planet:
num_of_ships_from_planet += enemy_fleet.num_ships()
scoring += num_of_ships_to_planet * 0.1
return scoring
def do_turn(pw):
for myPlanet in pw.my_planets():
planetRating = {score(myPlanet, x, pw) : x for x in pw.not_my_planets()}
d = {key:planetRating[key] for key in sorted(planetRating.keys(), reverse=True)}
for i, v in d.items():
if v.owner() == 1:
continue
if myPlanet.num_ships() > v.num_ships() + (v.growth_rate() * 6):
pw.issue_order(myPlanet, v, v.num_ships() + (v.growth_rate() * 6) + 1)
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment