Mixed-Unit-Tactics

I don’t know what to do I tried to do it on my own and I cant figure out the “palaside” part of the code

// Practice using modulo to loop over an array

// Choose the mix and order of units you want to summon by populating this array:
var summonTypes = ["soldier", "soldier","archer"];

function summonTroops() {
    // Use % to wrap around the summonTypes array based on hero.built.length
    //var type = summonTypes[???];
    var type = summonTypes[hero.built.length % hero.summonTypes.length];
    if (hero.gold >= hero.summon(type)) {
        hero.summon(type);
    }
}
function commandTroops(){
    var friends = hero.findFriends();
    var enemies = hero.findEnemies();
    for (var i = 0, i<friends.length, i++){
        var friend = friends[i];
        var enemy = hero.findNearest(enemies);
        if (friend.type == "palisade") {
            if (enemy) {
                hero.command(friend, "attack", enemy);
            }
        }
    }
}
function pickUpCoins(){
    var coins = hero.findItems();
    var coin = hero.findNearest(coins);
    if (coin) {
        hero.move(coin.pos);
    }
}

while(true) {
    summonTroops();
    commandTroops();
    pickUpCoins();
}


A palisade can’t attack.

what do you mean. It says in the hints that I should have type == “palisade”

It says skip over friends who have type “palisade”, not to include them and not command any other types. (Hint: use != which means “doesn’t equal”)
:lion: :lion: :lion:

so I made a few changes to my code and now when i run it, the soldiers will attack but my hero wont pick up coins until the enemies are attacking me.

// Practice using modulo to loop over an array

// Choose the mix and order of units you want to summon by populating this array{
var summonTypes = ["soldier", "soldier","archer"];

function summonTroops() {
    // Use % to wrap around the summonTypes array based on hero.built.length
    //var type = summonTypes[???];
    var type = summonTypes[hero.built.length % summonTypes.length];
    if (hero.gold > hero.summon(type)) {
        hero.summon(type);
    }
}
function commandTroops(){
    var friend = hero.findNearest(hero.findFriends());
    var enemy = hero.findNearest(hero.findEnemies());
        if (enemy && friend.type != "palisade"){
            if (friend){
                hero.command(friend, "attack", enemy);
        }
    }
}
function pickUpCoin() {
    // Collect coins
    var items = hero.findItems();
    var item = hero.findNearest(items);
        if (item) {
            hero.move(item.pos);
    }
}

while(true) {
    summonTroops();
    commandTroops();
    pickUpCoin();
}



Call the pickUpCoin(); function first

he still does the same thing

1 Like

I also have this problem if i put everything in functions. Paste the code for pickUpCoin(); in the while loop

he still wont move, he just stands there until the enemies get close

I think palisade hurts enemies on contact?

:slight_smile:

Self-contradiction oof

Haven’t been on CC for a long time