Harrowland possible bug


#1

I have this code in Harrowland in desert. When I run it, Tharin just goes to attack the Yak.

    loop{
    var enemy = this.findNearestEnemy();
    if(enemy){
        this.moveXY(44, 36);
        this.attack(enemy);
    }
}

Is this normal? What am I doing wrong?


#2

This is not a bug, yaks are considered enemies – though, they are more neutral and will only attack if you attack them first.

You should acquire glasses with the findEnemies and findNearest methods to make this level easier. Then you can use something like:

var enemy = this.findNearest(this.findEnemies().filter(function (enemy) {
    return enemy.type !== 'sand-yak';
}));
if (enemy) {
    // ...
}

Of course, it is still possible to do the level with just findNearestEnemy, but it may be more complicated. For instance, you can find the nearest enemy, and if it is an yak then check the distance to it and if it is too close then walk away from it.


#3

I’m going to apologies in advance - while I’m going to try to answer in Java, I’ve only been learning Python here. This will ignore the sand-yak.

 loop{
    var enemy = this.findNearestEnemy();
    if ((enemy) and (enemy.type!="sand-yak"){
        this.moveXY(44, 36);
        this.attack(enemy);
    }
}

Alternatively,

 loop{
    var enemy = this.findNearestEnemy();
    if(enemy){
        this.moveXY(44, 36);
        if enemy.type != "sand-yak"{
            this.attack(enemy);
        }
    }
}

[Once again, apologies if I got the above modified syntax wrong.]


#4

If you know Python, feel free to post in Python. I only read Python myself. :wink:


#5

You can just move to the middle then Tharin will attack the enemy hero