Protect the cage.
Put a soldier at each X.
points =
points[0] = {“x”: 33, “y”: 42}
points[1] = {“x”: 47, “y”: 42}
points[2] = {“x”: 33, “y”: 26}
points[3] = {“x”: 47, “y”: 26}
1. Collect 80 gold.
item = hero.findNearestItem()
if item:
hero.move(item.pos)
if hero.gold > hero.costOf(“soldier”):
for i in range(4):
hero.summon(“soldier”)
else:
hero.move(item.pos)
3. Send your soldiers into position.
while True:
friends = hero.findFriends()
for j in range(len(friends)):
point = points[j]
friend = friends[j]
enemy = friend.findNearestEnemy()
if enemy and enemy.team == “ogres” and friend.distanceTo(enemy) < 5:
# Command friend to attack.
hero.command(friend, “attack”, enemy)
pass
else:
# Command friend to move to point.
hero.command(friend, “move”, point)
pass
1 Like
Could you format your code as it is explaned here?
Formatting your code before posting code is essential to our community, and if you don’t we might not be able to help Everyone must know how to format ALL of your code properly. It’s really easy and only requires a very small amount of effort.
[Screen Shot 2020-04-04 at 11.55.07]
To post your code from the game , use the </> button or it won’t format properly. When you click the </> button, the following will appear:
[Screen Shot 2020-04-04 at 11.55.36]
Please paste ALL …
1 Like
# Protect the cage.
# Put a soldier at each X.
points = []
points[0] = {"x": 33, "y": 42}
points[1] = {"x": 47, "y": 42}
points[2] = {"x": 33, "y": 26}
points[3] = {"x": 47, "y": 26}
# 1. Collect 80 gold.
item = hero.findNearestItem()
if item:
hero.move(item.pos)
if hero.gold > hero.costOf("soldier"):
for i in range(4):
hero.summon("soldier")
else:
hero.move(item.pos)
# 3. Send your soldiers into position.
while True:
friends = hero.findFriends()
for j in range(len(friends)):
point = points[j]
friend = friends[j]
enemy = friend.findNearestEnemy()
if enemy and enemy.team == "ogres" and friend.distanceTo(enemy) < 5:
# Command friend to attack.
hero.command(friend, "attack", enemy)
pass
else:
# Command friend to move to point.
hero.command(friend, "move", point)
pass
2 Likes
is it like that
is it formatted well
2 Likes
Instead of this, put
while (hero.gold < 80):
#find and move to the nearest item
Also, delete this.
Do you need any more assistance at this level?
2 Likes
@Prosper_ONUIGBO have you finished the level?
1 Like