Stuck on Distracting Dungeon: peasant dying


I’m stuck on Distracting Dungeon. Before I can even turn right, my peasant is killed by the scouts. I’ve tried to protect my peasant by casting an invisibility spell on her, but she dies by the next corner. Could someone help guide me in the right direction?

Also, I had the Ring of Speed on before to go on ahead and kill the enemies, but then it made my hero and the peasant to walk in the wall.

Here’s my code:

var peasant = hero.findNearest(hero.findFriends());
while(true) {
    // Command your friend to build a decoy towards x + 1:
    hero.command(peasant, "buildXY", "decoy", peasant.pos.x+1, peasant.pos.y);
    var tDest = {x: hero.pos.x, y: hero.pos.y + 28};
    while(hero.distanceTo(tDest) > 1) {
        hero.command(peasant, "move", tDest);
    // Create a new x/y object +28 units away in the x dir:
    var n = {x: hero.pos.x+28, y: hero.pos.y};
    // Find the nearest enemy:
    var e = hero.findNearestEnemy();
    // While there is an enemy:
    while (e) {
        if (hero.canCast("invisibility", peasant)) {
            hero.cast("invisibility", peasant);
        // While the enemy's health is > 0:
        while ( > 0) {
            // Attack the enemy:
        // Update the variable to the next nearest enemy:
        e = hero.findNearestEnemy();
    // While friend's distance to the new x/y object > 1:
    while (peasant.distanceTo(n) > 1) {
        // Move the hero and peasant towards the x/y object:
        hero.command(peasant, "move", n);