I run out of time cause my peasants keep bumping into each other.
here is my code:
# Your goal is to collect coins / gems.
# This level is repeatable. If you win, the difficulty and rewards will increase.
# If you fail, you have to wait a day to resubmit.
# This level is an optional challenge level. You don't need to beat it to continue the campaign!
while True:
enemy = hero.findNearestEnemy()
friends = hero.findFriends()
for friend in friends:
item = friend.findNearest(friend.findItems())
hero.command(friend, "move", item.pos)
if enemy:
hero.attack(enemy)
Try to summon some troops that attack the enemies and you should also collect items yourself. (Here the ring of speed is really great)
Andrei
2 Likes
I have tried doesn’t work
2 Likes
Can you show me that code?
Andrei
1 Like
while True:
soldier = hero.findByType("soldier")
enemy = hero.findNearestEnemy()
friends = hero.findFriends()
if hero.gold > 20:
hero.summon("soldier")
hero.command(soldier, "attack", enemy)
if item:
hero.move(item.pos)
for friend in friends:
item = friend.findNearest(friend.findItems())
hero.command(friend, "move", item.pos)
if enemy:
hero.attack(enemy)
Delete this because you did not defined the variabile soldier, don’t you think?
Check if friend.type is peasant and only then command to collect coins, and make an else to that topic in what you command the friend to attack their nearest enemy.
Andrei
4 Likes