[SOLVED] Hunters and prey level crazy help

HELP ME!
THIS LEVEL WAS SO HARD! (mod edit: don’t spam letters please)

# Ogres are trying to take out your reindeer!
# Keep your archers back while summoning soldiers to attack.

def pickUpCoin():
    # Collect coins.
    item = hero.findNearestItem()
    if item:
        hero.move(item.pos)
    pass

def summonTroops():
    # Summon soldiers if you have the gold.
    if hero.gold > 20:
        hero.summon("soldier")
        pass
def commandSoldier():
    # Soldiers should attack enemies.
    friends = hero.findFriends()
    for friend in friends:
        
        enemy = soldier.findNearestEnemy()
        if friend:
            if friend.type == 'Soldier':
                if enemy:
                    hero.command(friend, "attack", enemy)
                    pass

# Write a commandArcher function to tell your archers what to do!
# It should take one argument that will represent the archer passed to the function when it's called.
# Archers should only attack enemies who are closer than 25 meters, otherwise, stay still.
def commandArcher():
    enemy = archer.findNearestEnemy
    distance = archer.distanceTo(enemy)
    if enemy and distance < 25:
        friends = hero.findFriends()
        for friend in friends:
            enemy = soldier.findNearestEnemy()
            if friend:
                if friend.type == 'Archer':
                    if enemy:
                        hero.command(friend, "attack", enemy)
                        pass
while True:
    pickUpCoin()
    summonTroops()
    friends = hero.findFriends()
    for friend in friends:
        if friend.type == "soldier":
            # This friend will be assigned to the variable soldier in commandSoldier
            commandSoldier(friend)
        elif friend.type == "archer":
            # Be sure to command your archers.
            commandArcher(friend)
            pass

Check your capitalition here.

Here you need to just command the archer to attack the enemy and what do you do if there is no enemy close to the archers?

Andrei

Never mind, i sovled it a Quintillion Septrillion times

{
    {
        {
            #griffin-rider}

#griffin-rider#griffin-rider

Please do not spam topics!

Andrei

1 Like

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.