Hunters and prey pretty bad bug

I beat it without working code

I even got the bonus

38%20PM

The level goals are based on certain criteria and good code isn’t necessarily one of those parameters.

What is your whole code? I’m curious how it passed with the error. The default for the archers is to move away from the reindeer attacking incoming enemies. When they move too far away, other ogres sneak in from behind. I’m wondering how your archers aren’t triggering that attack without being commanded.

Full code
---------------------------------------------------------------------------------------------------------------------------------

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

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

def summonTroops():
    # Summon soldiers if you have the gold.
    if hero.gold >= 40:
        hero.summon("soldier")
        hero.summon("archer")
    pass
    
# This function has an argument named soldier.
# Arguments are like variables.
# The value of an argument is determined when the function is called.
def commandSoldier(soldier):
    enemy = hero.findNearestEnemy()
    # Soldiers should attack enemies.
    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 cA(soldier):
    enemy = hero.findNearestEnemy()
    if enemy.pos.x >= 25:
        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

I know how, The hero makes one soldier, preventing a sneak attack, while the archers go off and deal with all of the ogres without dying.

You summoned an archer in the summonTroops() which wasn’t part of the directions. Apparently, that one archer prevents the sneak attack since he doesn’t follow commands or default code. Not as much a bug as it is a loophole.

Remove this one line, and you will see the fallout.

hero.summon("archer")

I must have interpereted the directions wrong.

It is still a major flaw because the level can be beaten with one line of code WITH the bonus

hero.summon("archer")

put that into the level with no other code

Notice the success tab and the single line of code