[SOLVED] Toil and Trouble soldiers die

In the toil and trouble level i have been having problems succeeding. i Have tried two methods and neither work.
the first is to tell them to attack nearest enemy

# Ogre Witches have some unpleasant surprises ready for you.

# Define a chooseTarget function which takes a friend argument
# Returns the a target to attack, depending on the type of friend.
# Soldiers should attack the witches, archers should attack nearest enemy.
def chooseTarget():
    archers = hero.findByType("archer")
    for archer in archers:
        
        aenemy = archer.findNearestEnemy()
        hero.command(archer, "attack", aenemy)
    soldiers = hero.findByType("soldier")
    for soldier in soldiers:
        
        Senemy = soldier.findNearestEnemy()
        hero.command(soldier, "attack", Senemy)
            
while True:
    friends = hero.findFriends()
    for friend in friends:
        # Use your chooseTarget function to decide what to attack.
        chooseTarget()
        pass

the second is to have the soldier attack the witches
this has the desired effect but 2 problems
1 the ogers kill the soldiers before they get to the witches
2 it is really slow

# Ogre Witches have some unpleasant surprises ready for you.

# Define a chooseTarget function which takes a friend argument
# Returns the a target to attack, depending on the type of friend.
# Soldiers should attack the witches, archers should attack nearest enemy.
def chooseTarget():
    archers = hero.findByType("archer")
    for archer in archers:
        
        aenemy = archer.findNearestEnemy()
        hero.command(archer, "attack", aenemy)
    soldiers = hero.findByType("soldier")
    for soldier in soldiers:
        
        Senemys = soldier.findEnemies()
        for senemy in Senemys:
            if senemy.type == "witch":
                hero.command(soldier, "attack", senemy)
                done = 1
        if done == 0:
            senemy2 = soldier.findNearestEnemy()
            hero.command(soldier, "attack", senemy2)
                

while True:
    friends = hero.findFriends()
    for friend in friends:
        # Use your chooseTarget function to decide what to attack.
        chooseTarget()
        pass

archers should target ogres, soldiers should target witches as witches can cast heal on ogres

1 Like

the archers should attack the ogres before the throwers?

here is the code adapted to your idea
the soldiers attack witches
and the archers attack ogres or if no ogres defend a point in the middle

# Ogre Witches have some unpleasant surprises ready for you.

# Define a chooseTarget function which takes a friend argument
# Returns the a target to attack, depending on the type of friend.
# Soldiers should attack the witches, archers should attack nearest enemy.
def chooseTarget():
    archers = hero.findByType("archer")
    for archer in archers:
        
        aenemy = archer.findNearestEnemy()
        if aenemy.type == "ogre":
            
            hero.command(archer, "attack", aenemy)
        else:
            hero.command(archer, "defend", {'x':39,'y':39})
    soldiers = hero.findByType("soldier")
    for soldier in soldiers:
        
        Senemys = soldier.findEnemies()
        for senemy in Senemys:
            if senemy.type == "witch":
                hero.command(soldier, "attack", senemy)
                done = 1
        if done == 0:
            senemy2 = soldier.findNearestEnemy()
            hero.command(soldier, "attack", senemy2)
                

while True:
    friends = hero.findFriends()
    for friend in friends:
        # Use your chooseTarget function to decide what to attack.
        chooseTarget()
        pass

for the record this code did not work

archers attacks nearest enemy

1 Like

i did that the archers kill throwers than try to kill ogres meanwhile the soldiers go for the witches are kill by the ogres and then the witches kill archers

paladins should heal soldiers

1 Like

wait a minute there are paladins? i dont see any

oops, i thought it was summit’s gate

2 Likes

mine worked just fine

here’s how i find em

if friend and friend.type is "soldier" and enemy and witch and witch.health > 0:
        hero.command(friend, "attack", witch)
    if friend and friend.type is "archer" and enemy:
        self.command(friend, "attack", enemy)

i think the problem is that the wiches heal and therefore i cant kill anything without losing friends to the witches poison

witches can’t heal themselves

they heal each other so even if everyone attacks a witch the other will heal them

in my code, 4 soldiers survived and all archers survived

then the archers can kill the ogres and then kill

did you use the emperors gloves? if the enemyies are close enogh u can cast it

no i didn’t, after the def, you should use for loop

while True:
    friends = self.findFriends()
    for friend in friends:
        # Use your chooseTarget function to decide what to attack.
        chooseTarget(friend)

yeah i am using it, it was there at the start