[SOLVED] SteelClaw Gap(C++) Help

// This level introduces the % operator, also known as the modulo operator.
// a % b returns the remainder of a divided by b
// This can be used to wrap around to the beginning of an array when an index might be greater than the length

// You start with 360 gold to build a mixture of soldiers and archers.
// this.built is an array of the troops you have built, ever.
// Here we use "this.built.length % summonTypes.length" to wrap around the summonTypes array
auto summonTroops() {
    auto type = summonTypes[hero.built.size() % summonTypes.size()];
    if(hero.gold >= hero.costOf(type)) {
        hero.summon(type);
    }
}

auto commandTroops() {
    auto friends = hero.findFriends();
    for(int friendIndex=0; friendIndex < friends.size(); friendIndex++) {
        auto friend = friends[friendIndex];
        // Use % to wrap around defendPoints based on friendIndex
        auto friend = friends[friendIndex];
        defendPoint = defendPoints[friendIndex % (defendPoints).length];
        // Command your minion to defend the defendPoint
        hero.command(friend, "defend", defendPoints);
    }
}


auto defendPoints = {{35, 63},{61, 63},{32, 26},{64, 26}};

auto summonTypes = {"soldier","soldier","soldier","soldier","archer","archer","archer","archer"};


int main() {
    while(true) {
        summonTroops();
        commandTroops();
    }
    
    return 0;
}

No no i mean defendPoint = defendPoints[friendIndex % (defendPoints).length] needs auto in front of it just like the auto friend = friends[friendIndex]; has it.

now he just stood and do nothin

// This level introduces the % operator, also known as the modulo operator.
// a % b returns the remainder of a divided by b
// This can be used to wrap around to the beginning of an array when an index might be greater than the length

// You start with 360 gold to build a mixture of soldiers and archers.
// this.built is an array of the troops you have built, ever.
// Here we use "this.built.length % summonTypes.length" to wrap around the summonTypes array
auto summonTroops() {
    auto type = summonTypes[hero.built.size() % summonTypes.size()];
    if(hero.gold >= hero.costOf(type)) {
        hero.summon(type);
    }
}

auto commandTroops() {
    auto friends = hero.findFriends();
    for(int friendIndex=0; friendIndex < friends.size(); friendIndex++) {
        auto friend = friends[friendIndex];
        // Use % to wrap around defendPoints based on friendIndex
        auto defendPoint = defendPoints[friendIndex % (defendPoints).length];
        // Command your minion to defend the defendPoint
        hero.command(friend, "defend", defendPoints);
    }
}


auto defendPoints = {{35, 63},{61, 63},{32, 26},{64, 26}};

auto summonTypes = {"soldier","soldier","soldier","soldier","archer","archer","archer","archer"};


int main() {
    while(true) {
        summonTroops();
        commandTroops();
    }
    
    return 0;
}

1 Like

he still stood(20 character)

defendPoints should be defendPoint because defendPoint is the array but defendPoint is the point you want the minion to defend.

ritic said to change defendPoint to defendPoints

He means the other way around; you should change defendPoints to defendPoint

i successed (20 character)