About stage of "clash-of-clones"


#1

hi I need your help.
he can beat clones and ogres except of ANYA.
Are there any problem??

// You’ll need good strategy and good equipment to win this one!
loop{
var enemy = this.findNearest(this.findEnemies());
var flag = this.findFlag();
if(flag){
this.pickUpFlag(flag);
}else if(enemy.type != “sand-yak”){
if (enemy){
this.attack(enemy);
this.attack(enemy);
this.attack(enemy);

    } else if(enemy.type == "ANYA"){
        var distance = this.distanceTo(enemy);
        if (distance < 10){
            disx = pos.x;
            disy = pos.y;
            this.moveXY(disx, disy);
        }
    }
}

}

Thanks


#2

Hello, hiro. Please format your code according to the FAQ.


Here’s what I can see off the top of my head:

You should put the if (enemy) { check before you check the type. Otherwise, you could break your code.

The type of Anya is captain, not her name. You can use her name with enemy.id.

You never define what pos is. You need to put the character whose position you want before the pos, such as enemy.pos.x or this.pos.y.


#3

Hi Gilver. Is this what you said about code and format? It haven’t worked yet. No error but hero is defeated by a captain.

indent preformatted text by 4 spaces

loop{
var enemy = this.findNearest(this.findEnemies());
var flag = this.findFlag();
if(flag){
this.pickUpFlag(flag);
}else if(enemy.type != “sand-yak”){
this.attack(enemy);
this.attack(enemy);
this.attack(enemy);
}
if(enemy){
if(enemy.type == “captain”){
var distance = this.distanceTo(enemy);
if (distance < 10){
pos = this.pos;
disx = this.pos.x;
disy = this.pos.y;
this.moveXY(disx, disy);
}
}
}


#4

Surround your code in triple backpacks, which are these characters: ` You should find the key in the upper left corner of your keyboard.

Well, the only thing I can say is to strategize. One way I’ve found is that the hero has the exact same equipment as you do, but only attacks the nearest enemy with the sword. Therefore, if you take away your sword, then they won’t have a sword either. Try that.