Hey guys. Can anyone help me with this level? Pender keeps walking into mines to attack a fangrider.
function chooseStrategy() {
let enemies = hero.findEnemies();
// If you can summon a griffin-rider, return "griffin-rider"
if (hero.gold >= hero.costOf("griffin-rider")) {
hero.summon("griffin-rider");
}
// If there is a fangrider on your side of the mines, return "fight-back"
let enemy = hero.findNearestEnemy();
let item = hero.findNearestItem();
if (enemy && enemy.type == "fangrider" && hero.distanceTo(enemy) >= 10) {
hero.attack(enemy);
} else {
// Otherwise, return "collect-coins"
if (item) {
hero.move(item.pos);
}
}
}
function commandAttack() {
// Command your griffin riders to attack ogres.
let friends = hero.findFriends();
for (let friend of friends) {
let enemy = friend.findNearestEnemy();
if (enemy) {
hero.command(friend, "attack", enemy);
}
}
}
function pickUpCoin() {
// Collect coins
let item = hero.findNearestItem();
if (item) {
hero.move(item.pos);
}
}
function heroAttack() {
// Your hero should attack fang riders that cross the minefield
let enemy = hero.findNearestEnemy();
if (enemy && enemy.type == "fangrider" && hero.distanceTo(enemy) >= 10) {
hero.attack(enemy);
}
}
while (true) {
commandAttack();
let strategy = chooseStrategy();
// Call a function, depending on what the current strategy is.
heroAttack();
pickUpCoin();
}