Skip to content

Instantly share code, notes, and snippets.

@yuvalyo
Created August 7, 2018 09:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuvalyo/7f3646bc9978231dfe9486b4b838dc4e to your computer and use it in GitHub Desktop.
Save yuvalyo/7f3646bc9978231dfe9486b4b838dc4e to your computer and use it in GitHub Desktop.
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