Defend the garrison -js


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) {
    } else if (enemy) {
        if (hero.isReady("cleave")) {
        } else if (hero.isReady("bash")) {
        } else {
    } else {

Could anyone help ?


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:


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.


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


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.


My equipment ,

I try wto fight that way.
Time out