Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Help "RING BEARER" [SOLVED]

this is level 7 in computer science 5, the objectives in this level are simple. help a peasant(the “ring bearer”) escape to the east. i need help on this level. my trops make it about halfway through the level then they stop moving altogether. here’s my code


function findSoldierOffset(soldiers, i) {
    var soldier = soldiers[i];
    var angle = i * 360 / soldiers.length;
    return radialToCartesian(5, angle);
}
function radialToCartesian(radius, degrees) {
    var radians = Math.PI / 180 * degrees;
    var xOffset = radius * Math.cos(radians);
    var yOffset = radius * Math.sin(radians);
    return {x: xOffset, y: yOffset};
}

var peasant = hero.findByType("peasant")[0];


while(true) {

     var soldiers = hero.findByType("soldier");
     for(var i = 0; i < soldiers.length; i ++) {

      var soldier = soldiers[i];
       var offset = findSoldierOffset(soldiers, i);
       var offsetX = peasant.pos.x + offset.x;
       var offsetY = peasant.pos.y + offset.y;
       var position = {"x": offsetY, "y": offsetY};
       hero.command(soldier, "move", position);
    }
    hero.move({x: hero.pos.x + 0.2, y: hero.pos.y});
}

I see you used the same variable for both X and Y. Switch the one to offsetX. I can’t tell if that is the only issue, but it’s a start.

var position = {"x": ***offsetY***, "y": offsetY};
1 Like

yea. i just saw that. i fixed it and it managed to work thanks.