Defend the garrison -js


#1

I stack I don’t see what is wrong with my solution .Hero is quite strong the power of life is 2117 but it’s not enough

while (true) {
    var enemy = hero.findNearestEnemy();
    var flag = hero.findFlag();
    if (flag) {
        hero.pickUpFlag(flag);
    } else if (enemy) {
        if (hero.isReady("cleave")) {
            hero.cleave(enemy);
        } else if (hero.isReady("bash")) {
            hero.bash(enemy);
        } else {
            hero.attack(enemy);
        }
    } else {
        hero.attack(enemy);
    }
}

Could anyone help ?


#2

That last hero.attack(enemy); means that if there is a flag, pick it up, else attack an enemy that may or may not exist. The first one is enough :slight_smile:


#3

Hellenar is correct - adding to that is the fact that there is no check for an enemy before it so if there is a point that there is no flag and no enemy your code could fail.


#4

Thanks for your help. I erased that line and run the code again, Anya lived a little bit longer but not enough ,maybe I should buy for her different type of equipment . Maybe 2100 it’s less then she need


#5

Can you post a screen shot of the equipment you are using?

Also, one of the things you’re supposed to use the flags for is to maneuver your hero to the left of the archers so that they attack anyone who comes through the gates and you take less damage. If you’re taking as much damage as you say, try staying out of the fight and letting the soldiers and archers do more. Use your flags so that you only step in and fight when when needed.


#6

My equipment ,


I try wto fight that way.
Time out


#7

Hi,

Not gonna lie was kinda proud first time beating this lvl. I had the same issue.

For me the trick was to only attack in case I planted a flag. You need to lure the enemies in front of the archers so you can deal with the backline casters. If you attack all enemies in sight you will indeed run out of time.

I also used multiple flag colours to make sure I could move without attacking anything


#8

Cool nice solution @zanox89! I just used ritic and the gift of the trees to beat the level