My Griffin-Riders do not try to attack Fangriders until they have crossed the mines, and they only shoot one spear.
function chooseStrategy() {
// If you can summon a griffin-rider, return "griffin-rider"
if (hero.gold >= hero.costOf("griffin-rider")) {
hero.summon("griffin-rider");
return "griffin-rider";
}
// If there is a fangrider on your side of the mines, return "fight-back"
let enemy = hero.findNearestEnemy();
if (enemy && enemy.type == "fangrider" && enemy.pos.x < 38) {
return "fight-back";
}
// Otherwise, return "collect-coins"
return "collect-coins";
}
function commandAttack() {
// Command your griffin riders to attack ogres.
let griffinRiders = hero.findFriends();
for (let griffinRider of griffinRiders) {
let enemy = griffinRider.findNearestEnemy();
if (enemy) {
hero.command(griffinRider, "attack", enemy);
}
}
}
function heroAttack() {
// Your hero should attack fang riders that cross the minefield
let enemy = hero.findNearestEnemy();
if (enemy && enemy.type == "fangrider" && enemy.pos.x < 38) {
hero.attack(enemy);
}
}
function pickUpCoin() {
// Collect coins
let item = hero.findNearestItem();
hero.move(item.pos);
}
while (true) {
let strategy = chooseStrategy();
// Call a function, depending on what the current strategy is.
if (strategy == "griffin-rider") {
commandAttack();
}
if (strategy == "fight-back") {
heroAttack();
}
if (strategy == "collect-coins") {
pickUpCoin();
}
}