Help on Reaping Fire Level


#1

When I play this level my Griffin Riders just get completely destroyed by the enemies within about 15 seconds and then they hit the mine field. Can someone look at my code and see where I can improve? I’m stumped.

// The goal is to survive for 30 seconds, and keep the mines intact for at least 30 seconds.
this.toggleFlowers(false);

this.chooseStrategy = function() {
    var enemies = this.findEnemies();
    var fangrider = this.findNearest(this.findByType("fangrider"));
    
    if(this.gold >= this.costOf("griffin-rider")){
        this.summon("griffin-rider");
    }

    if(fangrider && fangrider.pos.x < 36){
        return "fight-back";
    } else {
        return "collect-coins";
    }
};

this.commandAttack = function() {
    var griffins = this.findByType("griffin-rider");
    var enemies = this.findEnemies();
    for(var i = 0; i < griffins.length; i++){
        var griffin = griffins[i];
        var enemy = griffin.findNearest(enemies);
        if(enemy && enemy != "fangrider"){
            this.command(griffin, "attack", enemy);
        }
    }
};

this.pickUpCoin = function() {
    var coin = this.findNearest(this.findItems());
    if(coin){
        this.move(coin.pos);
    }
};

this.heroAttack = function() {
    // Your hero should attack fang riders that cross the minefield.
    var fangrider = this.findNearest(this.findByType("fangrider"));
    this.attack(fangrider);
};

loop {
    this.commandAttack();
    var strategy = this.chooseStrategy();
    if(strategy === "fight-back"){
        this.heroAttack();
    } else if(strategy === "collect-coins"){
        this.pickUpCoin();
    }
}

#2

There’s nothing wrong with your code, except perhaps that your griffin-riders will attack all enemies, since you check the enemy’s name, not the enemy’s type in this.commandAttack. Just keep submitting.


#3

Ended up having to use a Wizard with haste and long range attacks to make it work.


#4

My tactics was to keep the griffin riders away from the ogres. Something along these lines:

    if friend.distanceTo(enemy) < 10:
        # move back a bit
    else:
        # attack enemy

Cheers