# Help! mad maxer gets greedy

**URL:** <https://discourse.codecombat.com/t/help-mad-maxer-gets-greedy/12855>\
**Category:** Uncategorized\
**Created:** [November 3, 2017, 10:30am UTC](https://discourse.codecombat.com/t/help-mad-maxer-gets-greedy/12855 "2017-11-03T10:30:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Evil\_white](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/evil_white/32/7005_2.png) [@Evil\_white](https://discourse.codecombat.com/u/Evil_white)\
**Post date:** [November 3, 2017, 10:30am UTC](https://discourse.codecombat.com/t/help-mad-maxer-gets-greedy/12855/1 "2017-11-03T10:30:06Z")

</div>

At 20 seconds the hero rests against the wall.  
Level [https://codecombat.com/play/level/mad-maxer-gets-greedy](https://codecombat.com/play/level/mad-maxer-gets-greedy)?  
 ![Снимок](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/e/e0add207e0c46aa46493a5be487ac6a1e73aa04b.PNG)

```python
while True:
    bestCoin = None
    maxRating = 0
    coinIndex = 0
    coins = self.findItems()
    while coinIndex < len(coins):
        coin = coins[coinIndex]
        coinIndex += 1
        if coin.value / self.distanceTo(coin) > maxRating:
            maxRating = coin.value / self.distanceTo(coin)
            bestCoin = coin
        
    if bestCoin:
        self.moveXY(bestCoin.pos.x, bestCoin.pos.y)

```

---

<div class="post-metadata">

**Author:** ![MunkeyShynes](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/munkeyshynes/32/9277_2.png) [@MunkeyShynes](https://discourse.codecombat.com/u/MunkeyShynes)\
**Post date:** [November 3, 2017, 3:00pm UTC](https://discourse.codecombat.com/t/help-mad-maxer-gets-greedy/12855/2 "2017-11-03T15:00:16Z")

</div>

the only thing I did differently than your code was to define value and distance and use them in the first if statement. I don’t believe that makes any difference though. I believe the issue is that you incremented before the value / distance computation. I always increment last, after the computations.

```python
distance = hero.distanceTo(coin)
value = coin.value

```

Also, when running the code before submitting, it would never collect enough to beat the doppelganger. But when submitted, it wins every time.

---

<div class="post-metadata">

**Author:** ![Evil\_white](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/evil_white/32/7005_2.png) [@Evil\_white](https://discourse.codecombat.com/u/Evil_white)\
**Post date:** [November 3, 2017, 3:50pm UTC](https://discourse.codecombat.com/t/help-mad-maxer-gets-greedy/12855/3 "2017-11-03T15:50:02Z")

</div>

If I increment after computing, my code does not even start. Do not zayu why. All options pereprobyval, the hero rests against the wall at 20 seconds. Give your source, please.

---

<div class="post-metadata">

**Author:** ![MunkeyShynes](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/munkeyshynes/32/9277_2.png) [@MunkeyShynes](https://discourse.codecombat.com/u/MunkeyShynes)\
**Post date:** [November 3, 2017, 4:09pm UTC](https://discourse.codecombat.com/t/help-mad-maxer-gets-greedy/12855/4 "2017-11-03T16:09:48Z")

</div>

I just ran your code exactly as you have it written and it worked fine. Now, I think you have a gear problem. What glasses are you using? I’m using fine wooden glasses with range of 10 meters. If you’re using long range glasses it would explain why your character is trying to get to the other side and thus the “I can’t get there” message. Try using shorter range glasses.

---

<div class="post-metadata">

**Author:** ![Evil\_white](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/evil_white/32/7005_2.png) [@Evil\_white](https://discourse.codecombat.com/u/Evil_white)\
**Post date:** [November 3, 2017, 4:40pm UTC](https://discourse.codecombat.com/t/help-mad-maxer-gets-greedy/12855/5 "2017-11-03T16:40:10Z")

</div>

Thank you.) I used the “Sees through walls” glasses. The code works. but for some reason, at the end of the double collects one coin more. (Shoes “Leather Boots”)

---

<div class="post-metadata">

**Author:** ![Evil\_white](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/evil_white/32/7005_2.png) [@Evil\_white](https://discourse.codecombat.com/u/Evil_white)\
**Post date:** [November 3, 2017, 4:52pm UTC](https://discourse.codecombat.com/t/help-mad-maxer-gets-greedy/12855/6 "2017-11-03T16:52:03Z")

</div>

The problem is solved. Everything works, thank you!

---

<div class="post-metadata">

**Author:** ![MichaelS](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/michaels/32/10616_2.png) [@MichaelS](https://discourse.codecombat.com/u/MichaelS)\
**Post date:** [August 2, 2019, 2:03pm UTC](https://discourse.codecombat.com/t/help-mad-maxer-gets-greedy/12855/7 "2019-08-02T14:03:32Z")

</div>

I had the same problem with glasses and solve it with adding condition x \< 40 🤓

```python
if maxRating > 0 and coins[coinIndex].pos.x < 40:
    ...

```
