I have two problems. One: I can’t get the warrior to go after the coins. Two: I keep running out of hearts.
Here’s my code:
def findMostHealth(enemies):
target = None
targetHealth = 0
enemyIndex = 0
while enemyIndex < len(enemies):
enemy = enemies[enemyIndex]
if enemy.health > targetHealth:
target = enemy
targetHealth = enemy.health
enemyIndex += 1
return target
def valueOverDistance(item):
return item.value / hero.distanceTo(item)
# Return the item with the highest valueOverDistance(item)
def findBestItem(items):
bestItem = None
bestValue = 0
itemsIndex = 0
return bestItem
while True:
enemies = hero.findEnemies()
enemy = findMostHealth(enemies)
flag = hero.findFlag()
if enemy and enemy.health > 15:
while enemy.health > 0:
hero.attack(enemy)
else:
coins = hero.findItems()
coin = None
coin = findBestItem(coins)
if coin:
hero.moveXY(coin.pos.x, coin.pos.y)
if hero.health < 750:
hero.consecrate()
I don’t understand what’s wrong with it