this is my code but the griffin riders still get distracted by fangriders and attack them
// The goal is to survive for 30 seconds, and keep the mines intact for at least 30 seconds.
function chooseStrategy() {
var enemies = hero.findEnemies();
var enemy = hero.findNearest(enemies);
// If you can summon a griffin-rider, return "griffin-rider"
if (hero.gold >= hero.costOf("griffin-rider")) {
return "griffin-rider";
} else if (enemy && enemy.pos.x < 35) {
return "fight-back";
} else {
return "collect-coins";
} // If there is a fangrider on your side of the mines, return "fight-back"
// Otherwise, return "collect-coins"
}
function commandAttack() {
// Command your griffin riders to attack ogres.
var friends = hero.findFriends();
for (var i = 0; i < friends.length; i++) {
var friend = friends[i];
var enemy = hero.findNearestEnemy();
if (enemy && enemy.pos.x > 50) {
hero.command(friend, "attack", enemy);
}
}
}
function pickUpCoin() {
// Collect coins
var item = hero.findNearestItem();
if (item) {
hero.moveXY(item.pos.x, item.pos.y);
}
}
function heroAttack() {
// Your hero should attack fang riders that cross the minefield.
var enemy = hero.findNearestEnemy();
if (enemy && enemy.type != "fangrider") {
while (enemy.health > 0) {
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 {
pickUpCoin();
}
}