kode
// Your goal is to protect Reynaldo
var summonTypes = ['griffin-rider'];
function summonTroops() {
var types = summonTypes[hero.built.length % summonTypes.length];
if (hero.gold >= hero.costOf(types)) {
hero.summon(types);
}
}
// Find the paladin with the lowest health.
function lowestHealthPaladin() {
var lowestHealth = 99999;
var lowestFriend = null;
var friends = hero.findFriends();
for(var f=0; f < friends.length; f++) {
var friend = friends[f];
if(friend.type != "paladin") { continue; }
if(friend.health < lowestHealth && friend.health < friend.maxHealth) {
lowestHealth = friend.health;
lowestFriend = friend;
}
}
return lowestFriend;
}
function commandPaladin(paladin) {
// Heal the paladin with the lowest health using lowestHealthPaladin()
// You can use paladin.canCast("heal") and command(paladin, "cast", "heal", target)
// Paladins can also shield: command(paladin, "shield")
// And don't forget, they can attack, too!
var low = lowestHealthPaladin();
if (low) {
if (paladin.canCast("heal", low)) {
hero.command(paladin, "cast", "heal", low);
}
}
else if (paladin.health < 200) {
hero.command(paladin, "shield");
}
else {
var enemy = hero.findNearestEnemy();
if (enemy) {
hero.command(paladin, "attack", enemy);
}
}
}
function commandPeasant(peasant) {
var item = hero.findNearestItem();
if (item) {
hero.command(peasant, "move", item.pos);
}
}
function commandGriffin(griffin) {
var target = hero.findNearest(hero.findByType('warlock'));
if (! target) {
target = griffin.findNearestEnemy();
}
if (target) {
hero.command(griffin, "attack", target);
}
}
function commandFriends() {
// Command your friends.
var friends = hero.findFriends();
for(var i=0; i < friends.length; i++) {
var friend = friends[i];
if(friend.type == "peasant") {
commandPeasant(friend);
} else if(friend.type == "griffin-rider") {
commandGriffin(friend);
} else if(friend.type == "paladin") {
commandPaladin(friend);
}
}
}
while(true) {
commandFriends();
// Summon griffin riders!
summonTroops();
}
help i get infinite loops why?