# Level: Help with 'Ice Hunter'

#1

Hi guys, I got some problem with the level “Ice hunter” in cloudrip mountain. I don’t know how to attack all the enemies, my hero stops after having attacked successfully one small-yak and says "But he’s dead!"
I know that I should hunt for 4 yaks, but I don’t know how to continue with my code at the end… Thanks for your help!

``````# Hunt for 4 yaks. Choose only the small ones.
# Small yak names contain a "bos" substring.

# This function checks if a word contains a substring.
def isSubstring(word, substring):
# We iterate through the start indexes only.
rightEdge = len(word) - len(substring)
# Loop through the indexes of the word.
for i in range(rightEdge + 1):
# For each of them loop through the substring
for j in range(len(substring)):
# Use an offset for the word's indexes.
shiftedIndex = i + j
# If letters aren't the same:
if word[shiftedIndex] != substring[j]:
# Check the next start index in the word.
break
# If it was the last letter in the substring:
if j == len(substring) - 1:
# Then the substring is in the word.
return True
# We haven't found the substring in the word.
return False

# Loop through all enemies.
enemies = hero.findEnemies()
for e  in range(len(enemies)):
enemy = enemies[e]
# Use the function isSubstring to check
# if an enemy name (id) contains "bos":
word = enemy.id
substring = "bos"
while isSubstring(word, substring) is True:
hero.attack(enemy)
``````

#2

Its because you used a while loop while attacking.

``````# Loop through all enemies.
enemies = hero.findEnemies()
for e  in range(len(enemies)):
enemy = enemies[e]
# Use the function isSubstring to check
# if an enemy name (id) contains "bos":
word = enemy.id
substring = "bos"
while isSubstring(word, substring) is True:
hero.attack(enemy) #Your hero is constantly attcking this one enemy because
#the function is constantly returning true and never has
#the chance to look at the other enemies because this loop
#never ends.
``````

Try using something other than a while loop. You only need it to return true or false once and if your sword cant kill the yak in one hit. Use a loop so that it keeps on attacking it till its health is 0.

#3