Hi and thanks for reading this
I’ve been stuck in this level, somehow the total health of soldier is greater than ogres at the begining and I couldn’t even kill one ogre… if it’s something wrong with my code, could someone help me please? Many thank:sweat:
def sumHealth(units):
totalHealth = 0
unitsIndex = 0
while unitsIndex < len(units):
unit = units[unitsIndex]
if unit.health > totalHealth:
totalHealth += unit.health
unitsIndex += 1
return totalHealth
while True:
friends = hero.findFriends()
enemies = hero.findEnemies()
# Get the total health of your soldiers and the ogres.
soldierHealth = sumHealth(friends)
ogreHealth = sumHealth(enemies)
# Say "Attack" when your side has more total health.
if soldierHealth != ogreHealth:
if soldierHealth > ogreHealth:
hero.say("Attack")
pass