# Follow me on youtube channel Phy Tu
# Help with programming on Python, school math, physics
# https://www.youtube.com/channel/UCP5ycahCEZ24qmRRgNnko5Q
# Defend your towers in this replayable challenge level!
# Step on an X if you have 20 gold to build a soldier.
while True:
coins=hero.findItems()
coinIndex=0
nearest=None
nearestDistance=999
while coinIndex<len(coins):
coin=coins[coinIndex]
coinIndex+=1
distance=hero.distanceTo(coin)
if distance<nearestDistance:
nearest=coin
nearestDistance=distance
if hero.gold>=25 :
hero.moveXY(83,78)
if hero.gold>=26:
hero.moveXY(84, 51)
if hero.gold>=27:
hero.moveXY(84,22)
hero.moveXY(nearest.pos.x,nearest.pos.y)