While ogres were sleeping. Code doesn't work


#1
var points = [{x: 21, y: 8}, {x: 33, y: 8}, {x: 45, y: 8},
    {x: 57, y: 8}, {x: 68, y: 8}, {x: 68, y: 18},
    {x: 68, y: 28}, {x: 68, y: 38}, {x: 68, y: 48},
    {x: 68, y: 58}, {x: 56, y: 58}, {x: 44, y: 58}, 
    {x: 32, y: 58}, {x: 20, y: 58}, {x: 10, y: 60}];

var pointIndex = 0;

while (pointIndex < points.length) {
    var point = points[pointIndex];
    hero.moveXY(point.x, point.y);
    var enemy = hero.findNearestEnemy();
    var coin = hero.findNearestItem();
    // Attack only if the enemy.team is "ogres"
    // AND the enemy's health is less than 10
    if(enemy.team == "ogres" && enemy.health < 10) {
        hero.attack(enemy);
    }
    // Collect a coin if coin.value is less than 5
    // AND its distance is less than 7
    if(coin.value < 5 && coin.distance < 7) {
        hero.moveXY(coin.pos.x, coin.pos.y);
    }
    // Attack only if the enemy.health is less than 10
    // AND the enemy's type is "skeleton".
    if(enemy.health < 10 && enemy.type == "skeleton") {
        hero.attack(enemy);
    }
    pointIndex++;
}

Hero always pick up the farest coin so everybody can hear him.


#2

There is an interesting error in this code ( + 2 logic errors ). chichi_King is using coin.distance function that is not currently described anywhere.

      var coin = hero.findNearestItem();
      print('coin.distance: ' + coin.distance);

gives me this output in the console:

|Athena's Woodhouse| coin.distance: function(thang, fromEdges) {
    if (fromEdges == null) {
      fromEdges = false;
    }
    if (!(thang && (thang.isVector || thang.isThang || (!_.isNaN(thang.x + thang.y))))) {
      console.log('distance from', this.id, 'to', thang != null ? thang.id : void 0, 'did not work: isVector', thang != null ? thang.isVector : void 0, 'isThang', thang != null ? thang.isThang : void 0, 'x', thang != null ? thang.x : void 0, 'y', thang != null ? thang.y : void 0, 'keys', _.keys(thang));
      throw new ArgumentError("Find the distance to a target unit.", "distance", "target", "object", thang);
    }
    return Math.sqrt(this.distanceSquared(thang, fromEdges));
  }

I can’t understand how to use the second argument “fromEdges” . and when to use this function instead of distanceTo(object)?


#3

Thank you for that! :)))
I’ve used hero.distanseTo(coin); instead so it works


#4

Have you replaced the logic

if(condition1) action1;
if(condition2) action2;
if(condition3) action3;

This can work with a particular seed, but it’s not the right one.
/PS - off topic
. Have you used the console to create a session for “Bash ‘em all”?. I’ve maybe a solution, but a little effort is needed from you /


#5

Actually I have not. I didn’t get it.
I do not know how to use console in that case. I only know how to open it and search for mistakes.
Yes i’m asking because I’m just stuck with it. And sometimes HINTS is not enough.