I don’t really get how to solve this level, can anybody help me?
Heres my code
You are trapped. Don’t move, it’ll be painful.
This function checks if the enemy is in your attack range.
def inAttackRange(enemy):
distance = hero.distanceTo(enemy)
# Almost all swords have attack range of 3.
if distance <= 2:
return True
else:
return False
Attack ogres only when they’re within reach.
while True:
# Find the nearest enemy and store it in a variable.
enemy = hero.findNearestEnemy()
# Call inAttackRange(enemy), with the enemy as the argument
# and save the result in the variable canAttack.
if hero == inAttackRange(enemy):
return True
# If the result stored in canAttack is True, then attack!
if hero == canAttack == True:
canAttack = inAttackRange(enemy)
hero.cleave(enemy)
hero.attack(enemy)
pass