In Sarven siege level, I’m trying to make hero walk to the closest tower once he has collected 20 coins:
I wasn’t really expecting the following to work, I just took a wild guess how it might be done and tried it:
while True: while hero.gold < 20: coin = hero.findNearestItem() hero.moveXY(coin.pos.x, coin.pos.y) pass distance1 = hero.distanceTo(84,78) #position of 1st tower distance2 = hero.distanceTo(84, 51) #position of 2nd tower distance3 = hero.distanceTo(84, 22) #position of 3rd tower distances = [distance1, distance2, distance3] closest = min(distances) #then, something like: if closest == distance1: hero.moveXY(84, 78) elif closest == distance2: hero.moveXY(84, 51) else: hero.moveXY(84, 22)
for starters, I don’t even know if
distanceToworks like that, i.e. can I ask it for the distance to certain coordinates or do I have to store that position in a variable. If so, how do I do that?