This has happened with Gordon and the Pender.
function summonTroops() {
if (hero.gold >= hero.costOf("griffin-rider")) {
hero.summon("griffin-rider");
}
}
function commandTroops() {
let friends = hero.findFriends();
for (let friend of friends) {
let enemy = hero.findNearestEnemy();
if (enemy) {
hero.command(friend, "attack", enemy);
}
}
}
function collectCoin() {
let bestCoin = null;
let bestScore = 0;
let coins = hero.findItems();
for (let coin of coins) {
coin.score = coin.value / hero.distanceTo(coin);
if (coin.score > bestScore) {
bestScore = coin.score;
bestCoin = coin;
}
}
hero.move(bestCoin.pos);
}
function heroAttack() {
if (hero.canCast("shrink", hero)) {
hero.cast("shrink", hero);
}
}
while (true) {
summonTroops();
commandTroops();
collectCoin();
heroAttack();
}