while True:
enemy = hero.findNearestEnemy()
enemies = hero.findEnemies()
item = hero.findNearestItem()
items = hero.findItems()
itemDist = hero.distanceTo(item)
#find nearest enemy(s) move to closest teleporter if distance less than 10m
if enemy and hero.distanceTo(enemy) < 10:
hero.moveXY(20, 20)
closestTeleport = closest_teleport() #closestTeleport, move = closest_teleport
hero.moveXY(closestTeleport[0], closestTeleport[1])
#hero.move(move)
elif item:
hero.moveXY(item.pos.x, item.pos.y) #find nearest coin, move to coin
def closest_teleport():
teleportA = [5, 50]
teleportB = [6, 19]
teleportC = [76, 51]
teleportD = [76, 19]
distanceToA = distance_from_heros_position(teleportA[0], teleportA[1])
#distanceToA = distance_between_points(teleportA[0], teleportA[1], hero.pos.x, hero.pos.y)
distanceToB = distance_from_heros_position(teleportB[0], teleportB[1])
distanceToC = distance_from_heros_position(teleportC[0], teleportC[1])
distanceToD = distance_from_heros_position(teleportD[0], teleportD[1])
if distanceToA < distanceToB and distanceToA < distanceToC and distanceToA < distanceToD:
return teleportA#[0], teleportA[1])
elif distanceToB < distanceToA and distanceToB < distanceToC and distanceToB < distanceToD:
return teleportB#, {"x" : 5, "y" : 18}
elif distanceToC < distanceToA and distanceToC < distanceToB and distanceToC < distanceToD:
return teleportC
elif distanceToD < distanceToA and distanceToD < distanceToB and distanceToD < distanceToC:
return teleportD
def distance_from_heros_position(a, b) :
return distance_between_points(a, b, hero.pos.x, hero.pos.y)
def distance_between_points(a, b, c, d) :
return ((a - c)**2)**0.5 + (((b - d)**2)** 0.5
So, I have my hero walking tot he nearest teleport when enemies come within 10m. The problem I am having is the hero never*( in one iteration before the time out occurs he actually does) reaches the exact starting point of the teleporter, so he attempts to get there over and over. I was wondering if there was any way to hero.moveXY(just outside of teleport range) and then follow up with a hero.move(into the teleporter), or possibly a different solution??