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

Clash of Clones #188

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

# The function find the weakest enemy.
def findWeakestEnemy():
    enemies = hero.findEnemies()
    weakest = None
    leastHealth = 99999
    enemyIndex = 0
    # Loop through enemies:
    for enemy in enemies:
        # If an enemy's health is less than leastHealth:
        if enemy.health<leastHealth:
            # Make it the weakest 
            weakest=enemy
            # and set leastHealth to its health.
            leastHealth=enemy.health
    return weakest

while True:
    # Find the weakest enemy with the function:
    weakestShaman = findWeakestEnemy()
    # If the weakest enemy here:
    if weakestShaman:
        # Attack it!
        hero.attack(weakestShaman)