def findNearestTo( a ) : dis = 100000 pid = -1 for i in range( 1 , 10 ) : if ( i != a and distance( a , i ) < dis and not isMine( i ) ) : dis = distance( a , i ) pid = i return pid
def findNearestTo( a ) : x = 200000 y = -1 for i in range( 0 , 10 ) : if distance( a , i ) < x and not isMine( i ) : x = distance( a , i ) y = i return y
import time import math from myLib import moveToPortal from myLib import isMine from myLib import xOfPortal from myLib import yOfPortal # type codes below def distance( a , b ) : return math.sqrt( math.pow( xOfPortal( a ) - xOfPortal( b ) , 2 ) + math.pow( yOfPortal( a ) - yOfPortal( b ) , 2 ) ) def findNearestTo( a ) : dis = 100000 pid = -1 for i in range( 1 , 10 ) : if ( i != a and distance( a , i ) < dis and not isMine( i ) ) : dis = distance( a , i ) pid = i return pid nowPortal = 0 nextPortal = findNearestTo( nowPortal ) moveToPortal( nextPortal ) while True : if ( isMine( nextPortal ) ) : nowPortal = nextPortal nextPortal = findNearestTo( nowPortal ) if ( nextPortal == -1 ) : break moveToPortal( nextPortal )
import time import math from myLib import moveToPortal # moveToPortal( a ): triggers a movement toward a portal from myLib import isMine # isMine( a ): returns whether the portal is dominated by you from myLib import xOfPortal # xOfPortal( a ): returns the x-coordinate of the portal from myLib import yOfPortal # yOfPortal( a ): returns the y-coordinate of the portal nextPortal = 0 for nextPortal in range( 10 ) : moveToPortal( nextPortal ) while ( not isMine( nextPortal ) ) : pass