Last active
August 8, 2024 20:56
-
-
Save Gavriel770U/f0e1d910fc28c853fa799df812307be2 to your computer and use it in GitHub Desktop.
bot.py
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 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