-
-
Save yuvalyo/7f3646bc9978231dfe9486b4b838dc4e to your computer and use it in GitHub Desktop.
This file contains 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
import math | |
import random | |
def do_turn(pw): | |
planets = pw.planets() | |
if len(pw.my_planets()) == 0: | |
return | |
source = findGreatest(pw.my_planets()) | |
dest = findNearest(source,planets) | |
num_ships = source.num_ships() * 0.7 | |
if(source.num_ships() > 50): | |
pw.issue_order(source,dest,num_ships) | |
def findGreatest(planets): | |
max = 0 | |
maxP = 0 | |
for element in planets: | |
if element.num_ships() > max: | |
max = element.num_ships() | |
maxP = element | |
return maxP | |
def findDistance(home, Dest): | |
dist = math.hypot(home.x() - Dest.x(), home.y() - Dest.y()) | |
return dist | |
def findNearest(home,planets): | |
currDist = 50000 | |
finalDest = home | |
for dest in planets: | |
if dest.owner() != 1 and findDistance(home,dest) < currDist: | |
currDist = findDistance(home,dest) | |
finalDest = dest | |
return finalDest | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment