(Python): Hunter's Prey

Alright y’alls are getting #off-topic let’s start helping @phantomofthedark2

yes please.(20210)))

1 Like

So what is your new code

1 Like

This is my class break. I cant untill 12:00

1 Like

Ok. This is my new 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()
    if item:
        hero.move(item.pos)
    pass

def summonTroops():
    # Summon soldiers if you have the gold.
    if hero.gold > hero.costOf("soldier"):
        hero.summon("soldier")
    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():
    friends = hero.findFriends()
    for soldier in friends:
        enemy = soldier.findNearestEnemy()
        if enemy:
            hero.command(soldier, "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():
    friends = hero.findByType("archer", hero.findFriends())
    for friend in friends:
        enemy = friend.findNearestEnemy()
        if enemy:
            if hero.distanceTo(enemy) <= 25:
                
                if friend.type == "archer":
                    hero.command(friend, "attack", enemy)
                
            else:
                hero.command(friend, "move", {'x':24, 'y':47})

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

Okay try changing this

Into

friend.pos
1 Like

the same thing happens. This is the pic
image

This is the problem change that into this >=

1 Like

The same thing happens :sob:
Here is the 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()
    if item:
        hero.move(item.pos)
    pass

def summonTroops():
    # Summon soldiers if you have the gold.
    if hero.gold > hero.costOf("soldier"):
        hero.summon("soldier")
    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():
    friends = hero.findFriends()
    for soldier in friends:
        enemy = soldier.findNearestEnemy()
        if enemy:
            hero.command(soldier, "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():
    friends = hero.findByType("archer", hero.findFriends())
    for friend in friends:
        enemy = friend.findNearestEnemy()
        if enemy:
            if hero.distanceTo(enemy) >= 25:
                
                if friend.type == "archer":
                    hero.command(friend, "attack", enemy)
                
            else:
                hero.command(friend, "move", friend.pos)

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

1 Like

Anybody here? :scream:

Firstly: change the >= back to <=. You only want to attack when the ogres are closer than 25 meters, so you want to wait until the distance is less than or equal to (<=) 25.
However, the main problem is the fact that you’re using two for loops. One in the while true loop to isolate an individual soldier, which you then put into the commandSoldier and commandArcher functions, and a second for loop inside those functions. This isn’t going to work that well.
Inside the commandSoldier and commandArcher functions, you don’t need another for loop. You need to have an archer and soldier (respectively) variable inside the brackets of the function like:
def commandSoldier(soldier):
Then you command one individual soldier, you don’t make another for loop. The for loop in the while true loop has already singled out one individual soldier, who you can then command with the same code you have in the function, just without the for loop.
Does that make any sense? Just remove the for loops from inside the commanding functions, and put archer and soldier variables inside the brackets of those functions.
Danny

1 Like

Can you simplify it?

IS anybody here(2021)

just read what deadpool said.
if its confusing break it up into steps

Ok (2021202012020120201)

(credit to deadpool btw)
First:

Second:

3rd:

summary

just do all this in these steps. (If this works remember to give deadpool the solution thing since he wrote all of this)

Thank you so much! I have bin stuck since my bday

Good stuff Deadpool :slightly_smiling_face: bro all of yall are so much smarter than me lol

1 Like

anytime :grin:
thanks for helping deadpool

You too tho Falcon you’re one of the smartest pple here

1 Like