[SOLVED] Pender's Trial level Help Python

I’m having trouble on Pender’s trial:

def summonTroops():
    # These are just an example. Feel free to use griffin riders and/or other units!
    if hero.gold >= 40:
        hero.summon("soldier")
        hero.summon("archer")
def petcollect():
    pet.moveXY(13, 60)
    pet.moveXY(hero.pos.x, hero.pos.y)
while True:
    summonTroops()
    friends = hero.findFriends()
    # Iterate over all troops using a for loop. Make peasants collect coins. Combat troops fight. 
    #item = hero.findNearestItem()
    enemy = hero.findNearestEnemy()
    flag = hero.findFlag("green")
    
    for friend in friends:
        peasants = hero.findByType("peasant")
        for peasant in peasants:
            item = peasant.findNearestItem()
            if friend.type == "peasant":
                if item:
                    hero.command(friend, "move", item.pos)
        if friend.type != "peasant":
            if enemy:
                hero.command(friend, "attack", enemy)
                shamans = friend.findByType("shaman")
                for shaman in shamans:
                    if shaman:
                        hero.command(friend, "attack", shaman)
                    #else:
                    #    hero.command(friend, "attack", enemy)
                
            else:
                hero.command(friend, "attack", "Pender")
#        elif enemy and enemy.type == "shaman":
#            hero.command(friend, "attack", enemy)


I survive, the peasant survives, but I cant kill the last Brawler that tender summons. I also can’t get my troops to attack fender to end the challenge.

brawler was wrong. I mean giant.

btw, archer cost + soldier cost equals 45 not 40 :slight_smile:

fixed it. but still can’t kill the giant.

You’ll want your friends in formation, archers behind, and soldiers in front, this way, the soldiers make the enemies focus on them, acting as bait that does a bit of damage, and the archers deal the heavy damage from a distance. Here’s a little code snippet in JS from my code:

          else if (friend.type == "soldier") {
            if ((!(enemy)) && hero.time >= 45) enemy = hero.findByType("brawler")[0];
            if (!(enemy)) enemy = friend.findNearestEnemy();
            if (enemy && (friend.distanceTo(enemy) <= 30 || enemy.type == "brawler")) hero.command(friend, "attack", enemy);
            else {
                let index = hero.findByType("soldier").indexOf(friend); 
                hero.command(friend, "move", XY((20+((Math.floor(hero.findByType("archer").length/10)*8)))+(Math.floor(index/10)*8), 10+(Math.floor(index%10)*4)));
            }
        } else if (friend.type == "archer") {
            if (!(enemy) && hero.time >= 45) enemy = hero.findByType("brawler")[0];
            if (!(enemy)) enemy = friend.findNearestEnemy();
            if (enemy && (friend.distanceTo(enemy) <= 30 || enemy.type == "brawler")) hero.command(friend, "attack", enemy);
            else {
                let index = hero.findByType("archer").indexOf(friend); 
                hero.command(friend, "move", XY(16+(Math.floor(index/10)*8), 10+(Math.floor(index%10)*4)));
            }
        }

this code is pretty old, so it’s not formatted very well :]

Interesting. Nice to see someone going beyond the standard solution and trying different tactics.

You don’t need to attack Pender, just the ogres.

So you would just delete that part.

1 Like

i used Vectors to weave archers around the brawler like the ace of coders stratagy where ur achers surround okar

I managed to get a lucky spawn and beat it.