# Claim the coins while defeating the marauding ogres.
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
# Loop over the items array.
# Find the item with the highest valueOverDistance()
while itemsIndex < len(items):
item = items[itemsIndex]
if valueOverDistance > bestValue:
bestItem = item
bestValue = valueOverDistance(item)
itemsIndex += 1
return bestItem
while True:
enemies = hero.findEnemies()
enemy = findMostHealth(enemies)
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)
Please explain the problem.
he doesn’t collect anything
Sorry, but I don’t have that much time because I’m tired. Maybe @Chaboi_3000 or @MunkeyShynes could help you.
oh
thanks
by the way
Hi,
all you need to do is put an argument (something which goes in between the brackets of a function), in this case: item, here:
Otherwise the function valueOverDistance doesn’t have any “item” to compare value with distance.
Hope this helps!
it still says incomplete
# Claim the coins while defeating the marauding ogres.
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
# Loop over the items array.
# Find the item with the highest valueOverDistance()
while itemsIndex > len(items):
items = items[itemsIndex]
if valueOverDistance(item) > bestValue:
bestItem = item
bestValue = valueOverDistance()
itemsIndex += 1
return bestItem
while True:
enemies = hero.findEnemies()
enemy = findMostHealth(enemies)
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)
Why have you changed this line:
In your first post this line was right, now it’s wrong for the same reason that I said before.
If you change it back to what it was before it will work.
this?
bestValue = valueOverDistance(item)
Yeah, in both places.
(that should work)
if valueOverDistance(item) > bestValue:
bestItem = item
bestValue = valueOverDistance(item)
itemsIndex += 1
i tried this it doesn’t work
Ok, sorry there are two more things I missed the first time.
- this:
Look at it carefully, I think you can see it.
- and this:
This isn’t what was taught in the previous levels, well not quite. (> ----- <)
I’ve tried it now and it works.
im still kinda confused
Confused about what?
Ok,
I’ve tolded you quite clearly what to do.
Play around with it and it’ll work.