Now, edit the line 7 to auto friend = friends[i];
.
int main() {
// You can use findNearestEnemy() on your soldiers to get their nearest enemy instead of yours.
auto enemy = hero.findNearestEnemy();
while (true) {
auto friends = hero.findFriends();
for (int i = 0; i < sizeof friends / sizeof friends[0]; i++) {
// If they see an enemy then command to attack.
if (enemy) {
hero.command(friend, "attack", enemy);
}
// Command to move east by small steps.
}
}
return 0;
}
Why did you delete it?
By the way, @moonwatcher348 gave you the wrong for
…
It should be: for (int i = 0; i < friends.size(); i++) {
int main() {
// You can use findNearestEnemy() on your soldiers to get their nearest enemy instead of yours.
auto enemy = hero.findNearestEnemy();
while (true) {
auto friends = hero.findFriends();
for (int i = 0; i < friends.size(); i++) {
auto friends = friends[i];
// If they see an enemy then command to attack.
if (enemy) {
hero.command(friend, "attack", enemy);
}
// Command to move east by small steps.
}
}
return 0;
}
Nice, you almost did it.
Check the line with **.
Change it with auto friend = friends[i];
.
auto friend = friends[i];
Yes. Now paste that instead of the incorrect line and you should complete the level.
Seems like CodeCombat’s c++ is a bit different, yeah, that should work :]
One more thing how to move all soldier to right
Command them to move their x position+1 for x and their y position for y.
like this hero.command(friend, “move” {06, 52});
No, here is a hint: play with friend’s x
and y
positions.
how…give more hint…hint
oo…like this?
hero.command(friend, “move” {x, y});
Ok. So, your friend’s position is {friend.pos.x, friend.pos.y}, right? To make them go left is {friend.pos.x-1, friend.pos.y}, to make them go right is {friend.pos.x+1, friend.pos.y}. Try to write the whole command yourself.
like this…hero.command(friend, “move”, {friend.pos.x+1, friend.pos.y});
so…the command attack hero.command(friend, “attack”, enemy);?