The fangriders attack, the minefields expode, all is lost... -- I need help with my code "Reaping Fire"


#1

There are no errors in my code but somehow I still cannot protect the minefields or survive in 30 seconds.

Source code:

// The goal is to survive for 30 seconds, and keep the mines intact for at least 30 seconds.

this.chooseStrategy = function() {
    var enemies = this.findEnemies();

    // If you can summon a griffin-rider, return "griffin-rider"
    if (this.gold >= this.costOf("griffin-rider")) {
        return "griffin-rider";
    }
    // If there is a fangrider on your side of the mines, return "fight-back"
    for (var i = 0; i < enemies.length; i++) {
        var enemy = enemies[i];
        if (enemy.type == "fangrider") {
            return "fight-back";
        } else {
            return "collect-coins";
        }
    }
    // Otherwise, return "collect-coins"
};

this.commandAttack = function() {
    // Command your griffin riders to attack ogres.
    var friends = this.findFriends();
    for (var j = 0; j < friends.length; j++) {
        var friend = friends[j];
        var enemy = friend.findNearest(friend.findEnemies());
        if (enemy && enemy.type != "fangrider") {
            this.command(friend, "attack", enemy);
        }
    }
    
};

this.pickUpCoin = function() {
    // Collect coins
    var items = this.findItems();
    var nearest = this.findNearest(items);
    if (nearest) {
        this.move(nearest.pos);
    }
};

this.heroAttack = function() {
    // Your hero should attack fang riders that cross the minefield.
    var enemy = this.findNearest(this.findEnemies());
    if (enemy && enemy.type == "fangrider" && enemy.pos.x < 38) {
        if (this.isReady("bash")) {
            this.bash(enemy);
        } else {
            this.attack(enemy);
        }
    }
};

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

#2

I believe your problem is this: there is no type "fangrider". Instead, the type is "fang-rider".


#3

I tried adding the hyphen but it instead hindered my character from attacking.
No, I do not believe that this is the problem, but thanks for suggesting it.


#4

If your hero tries to attack an enemy out of range, it won’t be able to command your minions while it to move into range. So try only attacking when in range, else this.move into attacking range.

The fangrider’s type is "fangrider", you had that right.

Also, you’ll probably need >= 700 health and maybe a good sword (kithsteel blade or higher?)

And try submitting multiple times, the seeds can cause the enemy spawns to vary by a lot.


#5

U can try another approach. I passed that lvl without griffin-riders at all.

I wont tell the whole story but here is two hints, U can figure out the rest :wink:

  • peasants can also collect coins
  • jumping boots are quite useful on this map

I had written like 120 lines of code for this map but got some infinite loop in it so implemented only half, I managed to survive for 36 sec which is enough to complete it

Best luck :smile:


#6

Thanks, the strategy only works on a particular seed but I’m satisfied that it finally resolved my problem. I’ll assume that I will aim for the bonus once I have better armor.