Please help on level Sarven Desert - Fair Battle


#1

Hi and thanks for reading this :slight_smile:

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

#2

don’t post the same post in 2 places please. (Especially since you only waited 43 minutes between your posts)


#3

Hi SuperSmacker, sorry for the additional post
:sweat_smile: