// 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
defendPoint == defendPoints & friendindex;
// Command your minion to defend the defendPoint
hero.command(friend, "defend", defendPoitns);
}
}
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;
}
// 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
defendPoints % friendIndex;
// 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;
}
// 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
defendPoint = defendPoints[friendIndex % length.(defendPoints)];
// 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;
}
defendPoints is a array
ur legit commanding ur soldier to defend fort ticonderoga while going to costco or pizza, a soldier can’t be at 2 places at once