Reaping fire help (javascript)

I don’t know what I did wrong. Can somebody please help?
My code is below:

> // The goal is to survive for 30 seconds, and keep the mines intact for at least 30 seconds.
> 
> function chooseStrategy() {
>     var enemies = hero.findEnemies();
>     // If you can summon a griffin-rider, return "griffin-rider"
>     if (hero.gold >= hero.costOf("griffin-rider")) {
>         return "griffin-rider";
>     }
>     // If there is a fangrider on your side of the mines, return "fight-back"
>     var fangrider = hero.findByType("fangrider");
>     if (fangrider) {
>         return "fight-back";
>     }
>     // Otherwise, return "collect-coins"
>     else {
>         return "collect-coins";
>     }
> }
> 
> function commandAttack() {
>     // Command your griffin riders to attack ogres.
>     var friends = hero.findByType("thrower", hero.findFriends());
>     for (var i = 0; i <= friends.length; i += 1){
>         var friend = friends[i];
>         var enemy = hero.findNearestEnemy();
>         if (friend) {
>             if (enemy && enemy.type == "ogre") {
>                 hero.command(friend, "attack", enemy);
>             }
>         }
>     }
> }
> 
> function pickUpCoin() {
>     // Collect coins
>     var coin = hero.findNearestItem();
>     if (coin) {
>         hero.moveXY(coin.pos.x, coin.pos.y);
>     }
> }
> 
> function heroAttack() {
>     // Your hero should attack fang riders that cross the minefield.
>     var enemy = hero.findNearestEnemy();
>     if (enemy && enemy.type == "fangrider") {
>         hero.attack(enemy);
>     }
> }
> 
> while(true) {
>     commandAttack();
>     var strategy = chooseStrategy();
>     // Call a function, depending on what the current strategy is.
>     if (strategy == "griffin-rider") {
>         hero.summon("griffin-rider");
>         commandAttack();
>     }
>     else if (strategy == "fight-back") {
>         heroAttack();
>     }
>     else if (strategy == "collect-coins") {
>         pickUpCoin();
>     }
> }
1 Like

Do you get an error? From what i can see you have it right. Maybe it could me an equipment issue. Take a screenshot of your equipment @freesat-106

2 Likes

very quick look:

> function commandAttack() {
>     // Command your griffin riders to attack ogres.
>    ` var friends = hero.findByType("thrower", hero.findFriends());`
>     for (var i = 0; i <= friends.length; i += 1){
>         var friend = friends[i];
>         var enemy = hero.findNearestEnemy();
>         if (friend) 
>             if (enemy && enemy.type == "ogre") 
>                 hero.command(friend, "attack", enemy);        
>     }
> }

seems wrong to me. Your enemies aren’t your friends:

>     // Command your griffin riders to attack ogres.
>    ` var friends = hero.findByType("thrower", hero.findFriends());`

and you must fight all foes , not only ogres:

 if (enemy && enemy.type == "ogre") 
2 Likes

I agree but you can change it just slightly. Put enemy.team instead of enemy.type

3 Likes

sorry, that was a typo.

ok, I changed it to enemy.team, and I fixed the typo, but it didn’t work. My griffin riders just stand there.

Maybe just change it to if enemy

1 Like

Thanks, that part worked @Archion, but a munchkin always detonates the mine field before my griffin riders can kill it.

You don’t have to protect the minefield forever. Just for 30 seconds

1 Like

I know, but it blows up before the 30 seconds is up.

Also, because I changed enemy.type to enemy, now my griffin riders chase after the fangriders, leaving the mine field undefended.:scream:

I think I know whats wrong. My hero doesn’t collect coins, so I keep running out of griffin riders. But I don’t understand why my hero isn’t collecting coins. Is there something wrong with the code below?


function chooseStrategy() {
    var enemies = hero.findEnemies();
    // If you can summon a griffin-rider, return "griffin-rider"
    if (hero.gold >= hero.costOf("griffin-rider")) {
        return "griffin-rider";
    }
    // If there is a fangrider on your side of the mines, return "fight-back"
    var fangrider = hero.findByType("fangrider");
    if (fangrider) {
        return "fight-back";
    }
    // Otherwise, return "collect-coins"
    else {
        return "collect-coins";
    }
}

function commandAttack() {
    // Command your griffin riders to attack ogres.
    var friends = hero.findByType("griffin-rider", hero.findFriends());
    for (var i = 0; i <= friends.length; i += 1){
        var friend = friends[i];
        var enemy = hero.findNearestEnemy();
        if (friend) {
            if (enemy && enemy.type != "fangrider") {
                hero.command(friend, "attack", enemy);
            }
        }
    }
}

function pickUpCoin() {
    // Collect coins
    var coin = hero.findNearestItem();
    if (coin) {
        hero.moveXY(coin.pos.x, coin.pos.y);
    }
}

function heroAttack() {
    // Your hero should attack fang riders that cross the minefield.
    var enemy = hero.findNearestEnemy();
    if (enemy && enemy.type == "fangrider") {
        if (enemy.pos.x <= 36) {
            hero.attack(enemy);
        }
    }
}

while(true) {
    commandAttack();
    var strategy = chooseStrategy();
    // Call a function, depending on what the current strategy is.
    if (strategy == "griffin-rider") {
        hero.summon("griffin-rider");
        commandAttack();
    }
    else if (strategy == "fight-back") {
        heroAttack();
    }
    else if (strategy == "collect-coins") {
        pickUpCoin();
    }
}

I didn’t check your code in the level and I have forgotten how I had passed it.
Your most important first job is to collect coins, so put it first and then other conditions

if (strategy == "collect-coins")  pickUpCoin(); // no need of { action;} if you have only one statement

and check the position of the fangrider
// If there is a fangrider on your side of the mines, return “fight-back”

    var fangrider = hero.findByType("fangrider");
    if (fangrider)  return "fight-back"; // partly right

I put pickUpCoins(); first, but my hero still isn’t collecting coins. What should I do?

I’ve tried to pass the level tweaking your code but didn’t succeed. I think my last advice / pickUpCoins() first / was not so good. Start from scratch and find other members problems and solutions. Most of them are in python but it’s easy to translate them to java-script. You can check {SOLVED}Reaping Fire (python) as many other topics.

2 Likes

You can do if enemy.type != "fandrider" LOL i just put “fandrider” :smile: @freesat-106

1 Like