here is my code
while(true) {
var enemy = hero.findNearestEnemy();
var friends=hero.findFriends();
var i=0;
if (hero.gold>20) {
this.summon("soldier");
}
while (i<friends.length) {
var friend=friends[i];
if (friend) {
hero.command(friend, "defend", hero);
}
}
if (hero.isReady("warcry")) {
hero.warcry();
}
else if (hero.isReady("throw")) {
hero.throw(enemy);
}
else {
hero.shield();
}
}