# \[help\] Serpent Savings mission

**URL:** <https://discourse.codecombat.com/t/help-serpent-savings-mission/19890>\
**Category:** Level Help\
**Created:** [December 22, 2019, 3:13am UTC](https://discourse.codecombat.com/t/help-serpent-savings-mission/19890 "2019-12-22T03:13:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ChainR](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chainr/32/11120_2.png) [@ChainR](https://discourse.codecombat.com/u/ChainR)\
**Post date:** [December 22, 2019, 3:13am UTC](https://discourse.codecombat.com/t/help-serpent-savings-mission/19890/1 "2019-12-22T03:13:59Z")

</div>

> **[CodeCombat - Coding games to learn Python and JavaScript](https://codecombat.com/play/level/serpent-savings)**
>
> Learn typed code through a programming game. Learn Python, JavaScript, and HTML as you solve puzzles and learn to make your own coding games and websites.

This link above is the hyperlink for the level. Could you see my code below? Actually I managed to beat the level once. But, I didn’t get the bonus, so I thought I should improve my script and I added VOD function you can see at the top of my code.

```python
# You cannot collect coins.
# Summon peasants to collect coins for you.
# Collecting coins spawns a growing 'tail' behind the peasants.
# When a peasant touches a tail, they are destroyed.
# Collect 200 gold to pass the level.
# The following APIs are available on your team's peasants: "snakeBackward"
# The following APIs are available on neutral peasants: "snakeBackward", "snakeHead", "snakeForward"

def VOD(collector, items):
    bestItem = None
    bestVOD = 0
    for i in items:
        dis = collector.distanceTo(i)
        if i.value / dis > bestVOD:
            bestItem = i
            bestVOD = i.value / dis
    return i

while True:
    friends = hero.findFriends()
    tails = hero.findEnemies()
    coins = hero.findItems()
    for friend in friends:
        if len(coins) > 0:
            if hero.canCast('haste'):
                hero.cast('haste', friend)
            # Command the peasant to collect a coin, while avoiding the tails.
            bestCoin = VOD(friend, coins)
            coinV = Vector.subtract(bestCoin.pos, friend.pos)
            coinV = Vector.normalize(coinV)
            coinV = Vector.multiply(coinV, 6)
            moveTo = Vector.add(friend.pos, coinV)
            if len(tails) > 0:
                for i in tails:
                    distance = friend.distanceTo(i)        
                    if distance < 7:
                        tailV = Vector.subtract(friend.pos, i.pos)
                        tailV = Vector.normalize(tailV)
                        tailV = Vector.multiply(tailV, 3)
                        moveTo = Vector.add(moveTo, tailV)
                        hero.command(friend, 'move', moveTo)
                    else:
                        hero.command(friend, 'move', moveTo)
            else:
                hero.command(friend, 'move', moveTo)
                
        pass

```

Then, my peasant started to act weird. Even if a bronze coin pops up far away, he immediately turns his way, which means the Value Over Distance is not working here. Without this function, he was able to do his job properly, so I think putting VOD functions with Vectors is something behind this problem, but I don’t get it at all no matter what.

Plus, if you would, please look at my another posts that have not been answered. I’m still waiting for the answers. Here are my links. Thank you.

> [@Help: I can't beat Grim Determination](https://discourse.codecombat.com/t/help-i-cant-beat-grim-determination/19848/3):
>
> Mod edit: solution removed I managed to beat the level with this code above. I get the sense that the relation between hero.attack(enemy) and hero.command(someone, ‘attack’, enemy) is like the one between hero.move(pos) and hero.moveXY(x,y). Only the one time attack code and one step forward code go well together with while loop. So the griffin riders worked as I intended. And my paladins did their job perfectly. But still, I don’t get the exact idea behind the paladin part. Please if you coul…

> [@Is it a bug? I can't assign a value (Match Cord)](https://discourse.codecombat.com/t/is-it-a-bug-i-cant-assign-a-value-match-cord/19857):
>
> fieldMap = hero.findFriends()[0].getMap() hero.say(fieldMap[0]) mine = "x" empty = "." mineDistance = 5 firstXPos = 15 firstYPos = 40 hero.say(fieldMap[15]) # says .............x............. (which is the last mine near the boss) hero.say(fieldMap[15][13]) # says x newMap = fieldMap newMap[15][13] = 'o' hero.say(newMap[15]) # says .............x............., why not .............o.............? hero.say(newMap[15][13]) # says x, again, why didn't my hero say o instead of x? Please look a…

---

<div class="post-metadata">

**Author:** ![ChainR](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chainr/32/11120_2.png) [@ChainR](https://discourse.codecombat.com/u/ChainR)\
**Post date:** [December 23, 2019, 12:26am UTC](https://discourse.codecombat.com/t/help-serpent-savings-mission/19890/2 "2019-12-23T00:26:46Z")

</div>

oh I was so stupid why return i ☹  
sorry for the trouble.  
but I’m still looking for answers for the two posts I uploaded.  
(I still didn’t get the bonus in this lvl tho)
