while True:
# Move to the nearest coin.
# Use move instead of moveXY so you can command constantly.
coin = hero.findNearestItem()
hero.move(coin.pos)
hero.say("I need coins!")
# If you have funds for a soldier, summon one.
if hero.gold > hero.costOf("soldier"):
hero.say("I should summon something here!")
enemy = hero.findNearest(hero.findEnemies())
if enemy:
soldiers = hero.findFriends()
soldierIndex = 0
soldier = soldiers[soldierIndex]
# Loop over all your soldiers and order them to attack.
while True:
# Use the 'attack' command to make your soldiers attack.
#hero.command(soldier, "attack", enemy)
hero.command(soldier, "attack", enemy)
I don’t really understand what to put at the end
while True:
# Move to the nearest coin.
# Use move instead of moveXY so you can command constantly.
coin = hero.findNearestItem()
hero.move(coin.pos)
hero.say("I need coins!")
# If you have funds for a soldier, summon one.
if hero.gold > hero.costOf("soldier"):
hero.say("I should summon something here!")
enemy = hero.findNearest(hero.findEnemies())
if enemy:
soldiers = hero.findFriends()
soldierIndex = 0
soldier = soldiers[soldierIndex]
# Loop over all your soldiers and order them to attack.
while True:
# Use the 'attack' command to make your soldiers attack.
#hero.command(soldier, "attack", enemy)
hero.command(soldier, "attack", enemy)
My hero still doesn’t gather any coins so they can’t summon any soldiers. Am I supposed to use findNearestItem?
while True:
# Move to the nearest coin.
# Use move instead of moveXY so you can command constantly.
coin = hero.findNearestItem()
hero.move(coin.pos)
# If you have funds for a soldier, summon one.
if hero.gold > hero.costOf("soldier"):
hero.summon("soldier")
enemy = hero.findNearest(hero.findEnemies())
if enemy:
soldiers = hero.findFriends()
soldierIndex = 0
soldier = soldiers[soldierIndex]
# Loop over all your soldiers and order them to attack.
while True:
# Use the 'attack' command to make your soldiers attack.
#hero.command(soldier, "attack", enemy)
hero.command(soldier, "attack", enemy)
while True:
# Move to the nearest coin.
# Use move instead of moveXY so you can command constantly.
coin = hero.findNearestItem()
hero.move(coin.pos)
# If you have funds for a soldier, summon one.
if hero.gold > hero.costOf("soldier"):
hero.summon("soldier")
enemy = hero.findNearest(hero.findEnemies())
if enemy:
soldiers = hero.findFriends()
soldierIndex = 0
soldier = soldiers[soldierIndex]
# Loop over all your soldiers and order them to attack.
while len(soldiers) > [soldierIndex]:
# Use the 'attack' command to make your soldiers attack.
#hero.command(soldier, "attack", enemy)
soldier = soldiers[soldierIndex]
hero.command(soldier, "attack", enemy)
soldierIndex += 1
It seems that my hero ignores the presence of the ogres, and keep collecting coins. They have summoned the soldiers but don’t tell them to do anything
# Gather coins to summon soldiers and have them attack the enemy.
while True:
# Move to the nearest coin.
# Use move instead of moveXY so you can command constantly.
coin = hero.findNearestItem()
if coin:
hero.move(coin.pos)
# If you have funds for a soldier, summon one.
if hero.gold > hero.costOf("soldier"):
hero.summon("soldier")
enemy = hero.findNearest(hero.findEnemies())
if enemy:
soldiers = hero.findFriends()
soldierIndex = 0
soldier = soldiers[soldierIndex]
# Loop over all your soldiers and order them to attack.
while len(soldiers) > [soldierIndex]:
# Use the 'attack' command to make your soldiers attack.
#hero.command(soldier, "attack", enemy)
soldier = soldiers[soldierIndex]
hero.command(soldier, "attack", enemy)
soldierIndex += 1
Your first definition of soldier is not actually being used…you re-define soldier in the while loop, anyway.
Think about how you are defining your while statement…[soldierIndex] is pointing to an array element, not a counter. Without the brackets, it does then become a counter.
# Gather coins to summon soldiers and have them attack the enemy.
while True:
# Move to the nearest coin.
# Use move instead of moveXY so you can command constantly.
item = hero.findNearestItem()
hero.moveXY(item.pos.x, item.pos.y)
# If you have funds for a soldier, summon one.
if hero.gold > hero.costOf("soldier"):
hero.summon("soldier")
enemy = hero.findNearest(hero.findEnemies())
if enemy:
soldiers = hero.findFriends()
soldierIndex = 0
soldier = soldiers[soldierIndex]
# Loop over all your soldiers and order them to attack.
while len(soldiers) > soldierIndex:
# Use the 'attack' command to make your soldiers attack.
#hero.command(soldier, "attack", enemy)
hero.command(soldier, "attack", enemy)
soldierIndex += 1