Please help me my soldiers are not prioritizing witch
this.chooseTarget = function(friend){
if ( friend.type == "soldier" ){
var enemy = friend.findNearest(this.findByType("witch"));
return enemy;
} else if ( friend.type == "archer" ) {
enemy = friend.findNearest(friend.findEnemies());
return enemy;
}
};
loop {
var friends = this.findFriends();
for(var i=0; i < friends.length; i++) {
// Use your chooseTarget function to decide what to attack.
var friend = friends[i];
var target = this.chooseTarget(friend);
this.say(friend + target);
if (target){
this.command(friend, "attack", target);}
}
}
thanks