# You can find friends through walls, but not enemies.
# Watch out for smooth, frictionless ice patches!
enemy = hero.findNearestEnemy()
hero.cast("chain-lightning", enemy)
# def lowestHealthSoldier():
# lowestSoldier = False
# lowestHealth = 9999
# soldiers = hero.findByType("soldiers")
# for soldier in soldiers:
# if soldier.health < lowestHealth:
# lowestHealth = soldier.health
# lowestSoldier = soldier
# return lowestSoldier
def commandPaladin(paladin):
witch = paladin.findNearest(hero.findByType('witch'))
enemy = paladin.findNearest(hero.findEnemies())
if witch and witch.health > 0:
hero.command(paladin, "attack", witch)
elif enemy:
hero.command(paladin, "attack", enemy)
if paladin.canCast('heal'):
hero.command(paladin, "cast", 'heal', paladin)
def commandSoldier(soldier):
enemy = soldier.findNearestEnemy()
if enemy:
hero.command(soldier, "attack", enemy)
def commandArcher(archer):
enemy = archer.findNearestEnemy()
if enemy:
hero.command(archer, "attack", enemy)
def commandTroops():
friends = hero.findFriends()
for friend in friends:
if friend.type == 'soldier':
commandSoldier(friend)
if friend.type == 'archer':
commandArcher(friend)
if friend.type == 'paladin':
commandPaladin(friend)
def commandHero():
catapult = hero.findNearest(hero.findByType("catapult"))
enemy = hero.findNearestEnemy()
if catapult:
hero.attack(catapult)
elif enemy:
hero.attack(enemy)
while True:
commandTroops()
commandHero()
What is wrong with my code? My friends/units are stuck once in a while. Why did that happen? Can someone tell me please. Thank!