Help with Clash of Clones


#1

hello all,

I am so sorry to spam y’all. I’ll try to limit it next time.

I’m at Clash of Clones, and my strategy is to attack the clone me first, then the rangers, so I wrote this:

function findStrongestEnemy(enemies){
    var strongest = null;
    var strongestHealth = 0;
    var enemyIndex = 0;
    while (enemyIndex < enemies.length){
        var enemy = enemies[enemyIndex];
        if (enemy.health > strongestHealth){
            strongest = enemy;
            strongestHealth = enemy.health;
            enemyIndex++;
        }
        return strongest;
    }
}
while (true){
var enemy = hero.findEnemies;
var leader = findStrongestEnemy(enemy);
if(leader){
    hero.attack(leader);
}
    var farthest = null;
    var maxDistance = 0;
    var enemyIndex = 0;
    var enemies = hero.findEnemies;
    
    while(enemyIndex < enemies.length){
        var target = enemies[enemyIndex];
        enemyindex +=1;
        var distance = hero.distanceTo(target);
        if (distance > maxDistance){
            maxDistance = distance;
            farthest = target;
        }
    }
    if (farthest){
        if (target.health > 0){
            hero.attack(target);
        }
    }
}

However real me just stands there. Any help will be greatly appreciated!


#2

you have to see if the enemy exists by using if enemy:.


#3

uh please help me out here.


#4

If you search enemy hero read Easiest way to select the enemy hero.
Function findStrongestEnemy will return unexpected result. Try it yourself

while (true){
    var enemy = hero.findEnemies(); // obvious error 
    var leader = findStrongestEnemy(enemy);
    pet.say(leader);
    if(leader){
        hero.attack(leader);
    }
}