AlexeySapsay / Python_solution_CodeCombat_2018

In that repository I will post my sollution for codecombat.com games for study Python
1 stars 0 forks source link

Fair Battle #177

Open AlexeySapsay opened 6 years ago

AlexeySapsay commented 6 years ago
# Follow me on youtube  channel Phy Tu
# Help with programming on Python, school math, physics
# https://www.youtube.com/channel/UCP5ycahCEZ24qmRRgNnko5Q

# Attack when your soldiers' total health is greater
# than the ogres' total health

# This function return the sum of all the units' health.
def sumHealth(enemies):
    totalHealth = 0
    # Complete this function:
    #enemies=hero.findEnemies()
    enemyIndex=0
    while enemyIndex<len(enemies):
        totalHealth+=enemies[enemyIndex].health
        enemyIndex+=1
    return totalHealth

while True:
    friends = hero.findFriends()
    enemies = hero.findEnemies()
    # Get the total health of your soldiers and the ogres.
    if sumHealth(friends) <= sumHealth(enemies):
        hero.say("Wait")
    # Say "Attack" when your side has more total health.
    else:
        hero.say("ATTACK!!!")