Goals: Detonate the robobombs; save most of the soldiers
Robobombs explode when they die or touch an enemy.
Split up your soldiers so that they don’t all get exploded together.
The concept of spreading out soldiers to avoid splash damage hasn’t been covered in detail in other levels so it is a good idea.
The level is quite easy and is passable with a simple strategy but that’s fine for an introductory level.
My strategy involved repeatedly commanding ally[0] to go right and the others to go left. Of course, many improvements can be made such as commanding the rightmost ally to go right instead of the first but my initial strategy still passed
There is potential for more complicated levels involving soldiers and robobombs (or catapult shots).
Edit: Another thing, the starting code contained some python syntax that I had never seen before:
for index, friend in enumerate(friends):
# command soldiers
Some possibilities:
robobombs randomly approach from all sides
robobombs or catapult shots randomly fall from the sky above your soldiers
both of the above at the same time
fight robobombs mixed with other enemies
you control robobombs or artillery and need to hit clustered groups of enemies
I am having trouble figuring out how to pick out part of an index in the code. I can tell them all where to go, but not individuals…
loop:
friends = self.findFriends()
for index, friend in enumerate(friends, 0):
# Use the index to decide where to command each soldier to move.
for friend in friends:
self.command(friend[0], "move", {'x':16,'y':16})
self.command(friend, "move", {'x':50,'y':59})
the next to last line throws an error as I guess maybe I need to reference index or something. Any help just learning syntax to reference an index would be appreciated.
I don’t even understand howto code it I know what I wan to do but the
loop:
friends = self.findFriends()
for index, friend in enumerate(friends):
# Use the index to decide where to command each soldier to move.
doesn’t make any sence with me could you explane what it does
I had a hard time understanding how enumerate works based off what they give you. I watched some youtube and think I get it now. I beat this one by calling out the number or index assigned by the enumerate function in python. It is not elegant. I am sure someone can show a much better way. I will try in a moment. But I was able to just separate each friend by the index from enumerate. You could have created a list of positions and then assigned them matching the index’s from each I think would be less code.
loop:
friends = self.findFriends()
for index, friend in enumerate(friends, 0):
# Use the index to decide where to command each soldier to move.
for friend in friends:
self.command(friend[0], “move”, {‘x’:16,‘y’:16})
self.command(friend, “move”, {‘x’:50,‘y’:59})
This type of code is confusing can you guys make a video on how to do the level but not only that but how the code works step by step so we can get a deeper understanding because I think me like many don’t have anybody to teach us this so we can fully understand it.
I ran into the same problem but a little bit realizing that I want to do so:
while True:
enemies = hero.findEnemies()
enemy = hero.findNearest(enemies)
friends = hero.findFriends()
# Отправь первого солдата из массива друзей к врагу
friend = friends[0]
hero.command(friend, "attack", enemy)
# i in range(1, n) начав индекс со второго элемента!
for i in range(1, len(friends)):
friend = friends[i]
# Прикажи оставшимся солдатам ретироваться!
hero.command(friend, "move", {"x":friend.pos.x - 5, "y":friend.pos.y - 1})