# Mad maxer gets greedy problem

Hi my hero can’t get more coin and unfortunately he wants to go another side of the wall I can’t pass this level I tried a lot of options and I don’t know what is wrong with my code because all the time a get the same result

``````# Zbierz więcej monet niż twój  sobowtór
# You only have a few seconds to collect coins. Choose your path wisely!
# Try calculating "value / distance" to decide which coins to get.
while True:
bestCoin = None
minimumGoldDist = 33333
coinIndex = 0
coins = hero.findItems()
for coin in coins:
distance = hero.distanceTo(coin)/coin.value
if minimumGoldDist > distance:
bestCoin = coin
minimumGoldDist = distance
if bestCoin:
hero.moveXY(bestCoin.pos.x, bestCoin.pos.y)
pass

``````
1 Like

Here try to also check if hero.isPathClear(hero.pos, coin.pos) is true.

Andrei

1 Like

Hi CharlotteMoriarty, and welcome to the forum!

We’re happy to help you solve problems with your code, but ‘self’ hasn’t been used for several years. It’s much better if you write your own code, hmmm?

1 Like

Of course, as I wrote I was looking for many solutions and use a forum for help and check the option that was wrong with my code. If self hasn’t been used for a long time game should warn me and show any information or warning that I didn’t get . I spend few days with my one code thanks changing the way to pass it, thanks…

1 Like

.self still works, it just indicates that you aren’t writing your own code.
Post some of your own (however dodgy it is) and we’ll help you out. We just want to see some effort.
Danny

2 Likes

So the idea was to use PathClear to stop hero from trying to pass the wall. thank you very much for helping me to understand my problem

1 Like

Trying lots of ideas is good, and looking for help in different places is also a useful technique .

Have you solved the level?

1 Like

Yes, the tip from Andrei was really helpful. Now i know what was wrong. Thanks

1 Like