[SOLVED] Ring Bearer Please Help


#1
function findSoldierOffset(soldiers, i) {
    var soldier = soldiers[i];
    var angle = i * 360 / soldiers.length;
    return radialToCartesian(5, angle);
}

// This function does the math to determine the offset a soldier should stand at.
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]; 
// Use findByType to get an array of your soldiers.
while(true) {
    // Use a for-loop to iterate over your array of soldiers.
    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);
    
    }
    // Find the offset for a soldier.
    // Add the offset.x and offset.y to the peasant's pos.x and pos.y.
    // Command the soldier to move to the new offset position.
    // The hero should keep pace with the peasant!
    hero.move({x: hero.pos.x + 0.2, y: hero.pos.y});
}

So the problem is that the soldiers are stop moving in the middle.


#2

What map is this? Please give any other additional information about errors and etc.


#3

https://codecombat.com/play/level/ring-bearer?


#4

It’s in cloudrip mountain.


#5

The soldiers always stops in the middle. And I have no idea why.


#6

These lines aren’t needed, you can put these on one line. Use your var position to store the peasant.pos.x + offset.x and the peasant.pos.y + offset.y in the var position and command your soldier to move to “position” apart from that your code is right.


#7

Maan!
You rock!
Thank you.


#8

My pleasure. :grin: (20 chars)