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

Distraction Maneuver #167

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

# Protect the peasants!

# This is like findNearestEnemy but vice versus.
def findFurthestEnemy():
    enemies = hero.findEnemies()
    furthestEnemy = None
    maxDistance = 0
    enemyIndex = 0
    while enemyIndex < len(enemies):
        currentEnemy = enemies[enemyIndex]
        # Find the distance to currentEnemy:
        distance=hero.distanceTo(currentEnemy)
        # If that distance greater than maxDistance:
        if distance>maxDistance:
            # Reassign furthestEnemy to currentEnemy:
            furthestEnemy=currentEnemy
            # Reassign maxDistance to the distance:
            maxDistance=distance
        enemyIndex += 1
    return furthestEnemy

while True:
    # To protect peasants, hunt for furthest ogres.
    furthestOgre = findFurthestEnemy()
    if furthestOgre:
        while furthestOgre.health > 0:
            hero.attack(furthestOgre)