Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

[help] Serpent Savings mission

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.

# 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.


oh I was so stupid why return i :frowning:
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)