Help with Summits Gate

All of my troops die in the Outer Gate to the catapults, and they are all grouped up, how can I fix that?
My code is

def commandArcher(archer):
    enemy = hero.findNearestEnemy()
    hero.command(archer, "attack", enemy)

def commandPaladin(paladin):
    enemy = hero.findNearestEnemy()
    if paladin.canCast("heal") and hero.health <= 1000:
        hero.command(paladin, "cast" "heal", hero)
    elif enemy:
        hero.command(paladin, "attack", enemy)

def commandSoldier(soldier):
    enemy = hero.findNearestEnemy()
    catapult = hero.findByType("catapult")
    if catapult:
        for catapult in catapult:
            hero.command(soldier, "attack", catapult)
    else:
        hero.command(soldier, "attack", enemy)

def commandAll():
    friends = hero.findFriends()
    for friend in friends:
        if friend.type == "archer":
            commandArcher(friend)
        elif friend.type == "soldier":
            commandSoldier(friend)
        elif friend.type == "paladin":
            commandPaladin(friend)


while True:
    commandAll()
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.attack(enemy)

Oh and the link is https://codecombat.com/play/level/summits-gate

add a comma to the cast heal part

if paladin.canCast("heal") and hero.health <= 1000:
        hero.command(paladin, "cast"comma here "heal", hero)

yikes i type bad (20 chars)

When you command all your soldiers to attack the catapult they all move in one big group which the catapults can easily take out. Try and think of a way to space out your soldiers enough so they don’t all get taken out at once. If I remember correctly, the catapults target the closest enemy. Consider using someone as a decoy to draw their fire while you send the rest to attack. If you have a fast enough hero, they can dodge the fireballs.

also add a if enemy to the archers command function

1 Like

So I could command one soldier to target the catapult and then they would target that soldier, so then the other could take it out?

try adding else: hero.move({'x':hero.pos.x+1,'y':hero.pos.y})to your code in the while true loop

Like the while true loop with the commandAll() function?

yes

1 Like

I’m still having trouble trying to figure out how to get soldiers to go to different ones rather than grouping to the top one. Would I have to command soldier[0] and soldier[1] to go to the catapults so it targets them instead of the rest of the soldiers?

also you wrote game(20)

What do you mean game(20)?

you wrote game in the topic name instead of gate

1 Like

Which hero are you using and what gear do you have? Certain heroes allow for different strategy with their abilities. You can actually get the catapults to fire at each other and destroy themselves if you have a fast hero.

And yes, you can isolate one soldier with what you had. You would have to adjust how you add it to your code a bit to use that.

Ok, I will send a screenshot of my character and gear.
image
And I have 2033 gems

I would recommend doing a brawl to get gems and then get a better sword

such as…which one?

I don’t know which braw l did you get the latest

Ok now I have
image
but I can’t seem to figure out how I can get the catapults to target someone else. I’ll show my code again

def commandArcher(archer):
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.command(archer, "attack", enemy)

def commandPaladin(paladin):
    enemy = hero.findNearestEnemy()
    if paladin.canCast("heal") and hero.health <= 1000:
        hero.command(paladin, "cast", "heal", hero)
    elif enemy:
        hero.command(paladin, "attack", enemy)

def commandSoldier(soldier):
    soldiers = hero.findByType("soldier")
    enemy = hero.findNearestEnemy()
    catapults = hero.findByType("catapult")
    if catapult:
        for soldier in soldiers:
            for catapult in catapults:
                hero.command(soldier, "attack", catapult)
    else:
        hero.command(soldier, "attack", enemy)

def commandAll():
    friends = hero.findFriends()
    for friend in friends:
        if friend.type == "archer":
            commandArcher(friend)
        elif friend.type == "soldier":
            commandSoldier(friend)
        elif friend.type == "paladin":
            commandPaladin(friend)
soldiers = hero.findByType("soldier")
hero.command(soldiers[0], "move", {'x': 92, 'y': 6})
hero.command(soldiers[1], "move", {'x': 92, 'y': 60})
while True:
    commandAll()
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.attack(enemy)
    else:
        hero.move({'x':hero.pos.x+1,'y':hero.pos.y})

Okay how do you feel is there something really heavy on your back