Difficulty Beating Grim Determination (SOLVED Victory: BUG?)


#1

Original Text:
I am having difficulty beating this level. Everything works but they keep killing all of my paladins and Reynaldo. Would you, please give me suggestions for improvement?
/End Original Text

While watching the code run I kept noticing that the paladins would heal once and then stop healing. So I added a hero.say command to tell me if can cast was true or false. Once the code was run it was a victory.
There were a few other changes to the program done, but the paladins did not work correctly until I added the hero.say.

// Your goal is to protect Reynaldo
function commandPeasant(friend) {
    var coin = friend.findNearest(friend.findItems());
    if(coin){
        hero.command(friend, "move", coin.pos);
    }
}

function commandGriffin(friend) {
    //var enemies = hero.findByType('warlock', friend.findEnemies());
    var enemy = friend.findNearestEnemy();
    if(enemy){
        hero.command(friend, "attack", enemy);
    }
}
// Find the paladin with the lowest health.
function lowestHealthPaladin() {
    var lowestHealth = 99999;
    var lowestFriend = null;
    var friends = hero.findFriends();
    for(var f=0; f < friends.length; f++) {
        var friend = friends[f];
        if(friend.type != "paladin") { continue; }
        if(friend.health < lowestHealth && friend.health < friend.maxHealth) {
            lowestHealth = friend.health;
            lowestFriend = friend;
        }
    }
    return lowestFriend;
}

function commandPaladin(friend) {
    // Heal the paladin with the lowest health using lowestHealthPaladin()
    var hurtPaladin = lowestHealthPaladin();
    // You can use paladin.canCast("heal") and command(paladin, "cast", "heal", target)
    if(hurtPaladin && friend.canCast("heal")){
        hero.command(friend, "cast", "heal", hurtPaladin);
        hero.say(friend.canCast("heal"));
    }
    // Paladins can also shield: command(paladin, "shield")
    hero.command(friend, "shield");
    // And don't forget, they can attack, too!

    var enemy = friend.findNearest(hero.findEnemies());
    if (enemy) {
        hero.command(friend, "attack", enemy);
    }
}
function commandFriends() {
    // Command your friends.
    var friends = hero.findFriends();
    for(var i=0; i < friends.length; i++) {
        var friend = friends[i];
        if(friend.type == "peasant") {
            commandPeasant(friend);
        } else if(friend.type == "griffin-rider") {
            commandGriffin(friend);
        } else if(friend.type == "paladin") {
            commandPaladin(friend);
        }
    }
}

while(true) {
    commandFriends();
    // Summon griffin riders!
    if(hero.gold >= hero.costOf("griffin-rider")){
        hero.summon("griffin-rider");
    }
}