Advertisement
bhok

Untitled

Apr 15th, 2017
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. # Hunt for 4 yaks. Choose only the small ones.
  2. # Small yak names contain a "bos" substring.
  3.  
  4. # This function checks if a word contains a substring.
  5. def isSubstring(word, substring):
  6. # We iterate through the start indexes only.
  7. rightEdge = len(word) - len(substring)
  8. # Loop through the indexes of the word.
  9. for i in range(rightEdge + 1):
  10. # For each of them loop through the substring
  11. for j in range(len(substring)):
  12. # Use an offset for the word's indexes.
  13. shiftedIndex = i + j
  14. # If letters aren't the same:
  15. if word[shiftedIndex] != substring[j]:
  16. # Check the next start index in the word.
  17. break
  18. # If it was the last letter in the substring:
  19. if j == len(substring) - 1:
  20. # Then the substring is in the word.
  21. return True
  22. # We haven't found the substring in the word.
  23. return False
  24.  
  25. # Loop through all enemies.
  26. enemies = hero.findEnemies()
  27. for e in range(len(enemies)):
  28. enemy = enemies[e]
  29. # Use the function isSubstring to check
  30. # if an enemy name (id) contains "bos":
  31. enemyName = enemy.id
  32. hero.say(enemyName)
  33.  
  34. if isSubstring(enemyName,"bos"):
  35. # Then defeat it.
  36. while enemy.health > 0:
  37. hero.attack(enemyName)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement