this level is distraction maneuver.
I can’t find what is wrong
can you help me.
thanks a lot.
def findFurthest(units):
furthestUnit = None
maxDistance = 0
def findFurthest(units):
furthestUnit = None
maxDistance = 0
unitIndex = 0
while unitIndex < len(units):
target = hero.findNearestEnemy()
currentUnit = units[unitIndex]
# Find the distance to currentUnit:
distance = hero.distanceTo(target)
# If that distance greater than maxDistance:
if distance > maxDistance:
# Reassign furthestUnit and maxDistance:
maxDistance = distance
farthest = target
unitIndex += 1
return furthestUnit
It’s like findNearestEnemy but vice versus.
def findFurthestEnemy():
enemies = hero.findEnemies()
furthestEnemy = findFurthest(enemies)
# Return furthestEnemy:
return futhestUnit
The function makes the hero attack without distractions.
def attackWhileAlive(target):
# Attack target while it's health > 0:
while target.health > 0:
hero.attack(enemies)
pass
while True:
# To protect peasants, hunt for furthest ogres.
furthestOgre = findFurthestEnemy()
if furthestOgre:
attackWhileAlive(furthestOgre)