Restless-dead help java script

this is my code, please help


hero.moveXY(59, 23);
hero.moveXY(53, 36);
while (true) {
    var enemy = hero.findNearestEnemy();
    hero.attack(enemy);
    hero.attack(enemy);
    var item = hero.findNearestItem();
    if (item) {
        hero.moveXY(item.pos.x, item.pos.y);
    }
    hero.moveXY(37, 32);
    hero.moveXY(19, 40);
    while (hero.gold > hero.costOf("soldier")) {
        hero.say("Powinienem/am wezwać coś tutaj!");
        hero.summon("soldier");
    }
    var enemy = hero.findNearest(hero.findEnemies());
    if (enemy) {
        var soldiers = hero.findFriends();
        var soldierIndex = 0;
        while (soldierIndex < soldiers.length) {
            var soldier = soldiers[soldierIndex];
            hero.command(soldier, "move", {x: 50,y: 40 });
            var enemy = hero.findNearestEnemy();
            if (enemy) {
                hero.command(soldier, "attack", enemy);
                hero.moveXY(19, 39);
                hero.moveXY(53, 47);
            }
            soldierIndex++;
        }
    }
}

Are you having any specific problems? or is there just something you don’t understand?

my hero has too little energy (3510) to beat the skeletons, the soldiers can’t do it either

It would be a better plan to use flags rather than moveXY inside the while True loop. Otherwise you’ll have to keep doing the moveXY statements even when you’ve already got past that stage in the level. Also you need to add something in front of

Otherwise you’ll do it even if there aren’t any enemies.
Finally, I wouldn’t move this far:

It just means you take more damage to the yeti.
I can clarify this if you need me to, but please could you post your new code first.
Danny

while (true) {
    var enemy = hero.findNearestEnemy();
    var flag = hero.findFlag("green");
    if (flag) {
     
    if (hero.distanceTo(flag) < 20) {
                hero.pickUpFlag(flag);
}     var enemy = hero.findNearestEnemy();

    hero.attack(enemy);

  hero.attack(enemy);
    }
    var item = hero.findNearestItem();
    if (item) {
        hero.moveXY(item.pos.x, item.pos.y);
    }
  //  hero.moveXY(37, 32);
//    hero.moveXY(19, 40);
    while (hero.gold > hero.costOf("soldier")) {
        hero.say("Powinienem/am wezwać coś tutaj!");
        hero.summon("soldier");
    }
    var enemy = hero.findNearest(hero.findEnemies());
    if (enemy) {
        var soldiers = hero.findFriends();
        var soldierIndex = 0;
        while (soldierIndex < soldiers.length) {
            var soldier = soldiers[soldierIndex];
            hero.command(soldier, "move", {x: 50,y: 40 });
            var enemy = hero.findNearestEnemy();
            if (enemy) {
                hero.command(soldier, "attack", enemy);
  //              hero.moveXY(19, 39);
    //            hero.moveXY(53, 47);
            }
            soldierIndex++;
        }
    }
}

> Blockquote

I’ve got quite a few suggestions which almost make your hero win (you’ll have to try some different tactics to win, but with these tips it almost works, for me at least).

Your } from if (flag) { includes the var enemy and hero.attack(enemy);. You don’t really only want to attack an enemy when there’s a flag. Also, make sure you put if(enemy) in front the hero.attack(enemy). You might also only want to have one hero.attack(), if the code is looped (which it is), you don’t need two statements because it will just repeat anyway.

This kind of wastes time now, so you can probably remove it.

You might want to add something like && hero.time >= a certain number, so that you only summon soldiers in the right place, rather than having them lying around the map in inconvenient places.

You should do var enemy = soldier.findNearestEnemy() otherwise all the soldiers will attack the same skeleton, which is very inefficient and wastes most of their attack.
I hope this helps,
Danny

I took your first code, modified it and pasted it in another session taken from the leaderboard. You can see a flag, but in reality it hasn’t been used. Boss star I, Sword of the Forgotten.
Some soldiers died, if you want to see other strategies without casualties use the search i have posted 4 short animations. ( and creating the videos is the hardest thing :slight_smile: )

2 Likes

If to think from the game point, you’ll just get bored, when you get code to all levels.The game loses sense.And here, if we post solution, other players might read it too.That won’t be nice.

  1. Photoes/videos (any of related to you somehow)
2 Likes

can u delete my post from this

please delete this post

hi please delete this post till end

hi thx a lot, sorry for problem