[SOLVED] Help on Kelvintaph Crusader

Could you help me? After my troops defeat the witch, they stop and don’t attack the other enemies and I don’t know why. This is my code:

# You can find friends through walls, but not enemies.
# Watch out for smooth, frictionless ice patches!
def commandCaptain():
    enemies = hero.findEnemies()
    hero.cast("invisibility", hero)
    hero.moveXY(36, 8)
    hero.moveXY(48, 8)
    target = hero.findNearestEnemy()
    hero.cast("chain-lightning", target)
    enemies = hero.findEnemies()
    for enemy in enemies:
        if enemy.type == "catapult":
            hero.attack(enemy)
    hero.moveXY(78, 14)

def commandFriends():
    friends = hero.findFriends()
    for friend in friends:
        enemies = friend.findEnemies()
        if friend.type == "paladin":
            if friend.canCast("heal") and friend.health < 500:
                hero.command(friend, "cast", "heal", friend)
            else:
                hero.command(friend, "shield")
        elif friend.type == "archer":
            target = None
            enemies = friend.findEnemies()
            for enemy in enemies:
                if enemy.type == "witch" and enemy.health > 0:
                    target = enemy
            if target == None:
                target = enemies[0]
            hero.command(friend, "attack",target)
        elif friend.type == "soldier":
            k = 0
            for enemy in enemies:
                if enemy.type == "witch"and enemy.health > 0:
                    hero.command(friend, "attack", enemy)
                    k = 1
            if k == 0:
                hero.command(friend, "attack", friend.findNearest(friend.findEnemies()))
commandFriends()
commandCaptain()
while True:
    commandFriends()
    hero.moveXY(78, 14)
1 Like

And I don’t know what to put the paladin to do

So could someone help me find out what did I do wrong?

Hi, I’m a bit confused about your commanding the soldiers and archers bit.
You seem to have used two very different methods for the two troops and neither of them seem to work.
Maybe try something more simple, the hero.findNearest(hero.findByType(“witch”)) method might be helpful, paired with a simple if, elif.
Danny

I thought that I can’t find enemies on the order part of the wall.

Yes, you’re right, I completely forgot about that.
How about making a separate function for finding witches then?

def findWitch(enemies):
    # code---- involving a witch variable and a for loop
    return witch 

Or something.

Well, I think that may have been true at the level’s inception, but, try this (a modified snippet of my code):

        enemies = hero.findEnemies()
        witch = hero.findNearest(hero.findByType("witch"))
        if len(enemies) > 0 and witch:
            hero.say(witch.pos) # hero says "{x: 31.23, y: 57.86, z: 2.00}"

Would he be able to say the position if he could not see the witch?

This is my gear:

Ok and what should I put my paladin to do?

Well, given this is a challenge level (no guiding comments or helper code), and that there are innumerable strategies that could work…this is what worked for me. To specifically answer your question:

def commandPaladin(friend):
if can heal
heal weakest friend
if not, and health is below 200
shield
otherwise
attack

For the whole, I focused on the witch, using the archers in one corner and the paladin going direct. Once the witch was down, I moved the paladin down towards the south wall, acting as a decoy while everyone else beat it towards the exit. Once they reach a key spot, I set the paladin after them and then everyone exited.

Meanwhile, I toy with the catapults and brawlers, luring the brawlers in to cat range…once they are all dead, I take out the cats and exit.

2 Likes

And what should I put my soldiers to do?

1 Like

I had mine help in attacking the witch, then run like heck. Btw, the witch is the only enemy in the top section that needs to be killed, as she triggers the door. You can kill them all if you prefer, but it is not required.

Ok. Thanks for the help!

1 Like

This is my new code,but I don’t understand the error.

# You can find friends through walls, but not enemies.
# Watch out for smooth, frictionless ice patches!
def  lowestFriend(friends):
    friends = hero.findFriends()
    lowestHealth = 9999
    lowestFriend = None
    for friend in friends:
        if friend.health < lowestHealth:
            lowestFriend = friend
            lowestHealth = friend.health
    return lowestFriend

def commandCaptain():
    k = 0
    enemies = hero.findEnemies()
    for enemy in enemies:
        if enemy.type == "catapult":
            hero.attack(enemy)
            k = 1
    if k == 0:
        hero.moveXY(78, 14)


def chooseTarget(friend):
    enemies = friend.findEnemies()
    for enemy in enemies:
        if enemy.type == "witch":
            return enemy

def commandFriends():
    friends = hero.findFriends()
    lowestFriend = lowestFriend(friends)
    for friend in friends:
        enemies = friend.findEnemies()
        target = chooseTarget(friend)
        if friend.type == "paladin":
            if friend.canCast("heal"):
                hero.command(friend, "cast", "heal", lowestFriend)
            elif target and friend.health >= 200:
                hero.command(friend, "attack", target)
            elif target and friend.health < 200:
                hero.command(friend, "shield")
            elif jjj == 0:
                hero.command(friend, "move", {"x":5,"y":58})
                if friend.pos.x == 5:
                    jjj = 1
            elif jjj == 1:
                hero.command(friend, "move", {"x":61,"y":58})
                if friend.pos.x == 61:
                    jjj += 1
            else:
                hero.command(friend, "move", {"x":78,"y":40})
        elif friend.type == "archer":
            if target:
                hero.command(friend, "attack", target)
            elif j == 0:
                hero.command(friend, "move", {"x":33,"y":59})
                if friend.pos.x == 33:
                    j = 1
            elif j == 1:
                hero.command(friend, "move", {"x":61,"y":58})
                if friend.pos.x == 61:
                    j += 1
            else:
                hero.command(friend, "move", {"x":78,"y":40})
        elif friend.type == "soldier":
            if target:
                hero.command(friend, "attack", target)
            elif jj == 0:
                hero.command(friend, "move", {"x":61,"y":58})
                if friend.pos.x == 61:
                    jj = 1
            else:
                hero.command(friend, "move", {"x":78,"y":40})
commandFriends()
hero.cast("invisibility", hero)
hero.moveXY(52, 15)
target = hero.findNearestEnemy()
hero.cast("chain-lightning", target)
j = 0
jj = 0
jjj = 0
while True:
    commandFriends()
    commandCaptain()

1 Like

And this is the error:

1 Like

I solved that. But now I want to command my friends to move to a flag’s pozision. But they stay in place.
What am I doing wrong? This is my code:

# You can find friends through walls, but not enemies.
# Watch out for smooth, frictionless ice patches!
def  low(friends):
    friends = hero.findFriends()
    lowestHealth = 9999
    lowestFriend = None
    for friend in friends:
        if friend.health < lowestHealth:
            lowestFriend = friend
            lowestHealth = friend.health
    return lowestFriend

def commandCaptain():
    k = 0
    enemies = hero.findEnemies()
    for enemy in enemies:
        if enemy.type == "catapult":
            hero.attack(enemy)
            k = 1
    if k == 0:
        hero.moveXY(78, 14)


def chooseTarget(friend):
    enemies = friend.findEnemies()
    for enemy in enemies:
        if enemy.type == "witch":
            return enemy

def commandFriends():
    friends = hero.findFriends()
    lowestFriend = low(friends)
    flag = hero.findFlag("green")
    flag1 = hero.findFlag("violet")
    for friend in friends:
        enemies = friend.findEnemies()
        target = chooseTarget(friend)
        if friend.type == "paladin":
            if friend.canCast("heal"):
                hero.command(friend, "cast", "heal", lowestFriend)
            elif target and friend.health >= 200:
                hero.command(friend, "attack", target)
            elif target and friend.health < 200:
                hero.command(friend, "shield")
            else:
                hero.command(friend, "move", {"x":flag1.pos.x,"y":flag1.pos.y})
        elif friend.type == "archer":
            if target:
                hero.command(friend, "attack", target)
            #elif j == 0:
            #hero.command(friend, "move", {"x":33,"y":59})
            # if friend.pos.x == 33 and friend.pos.y == 59:
            #    j = 1
            # elif j == 1:
            #  hero.command(friend, "move", {"x":61,"y":58})
            #     if friend.pos.x == 61 and friend.pos.y == 58:
            #       j += 1
            # else:
            #   hero.command(friend, "move", {"x":78,"y":40})
            else:
                hero.command(friend, "move", {"x":flag.pos.x,"y":flag.pos.y})
        elif friend.type == "soldier":
            if target:
                hero.command(friend, "attack", target)
            else:
                hero.command(friend, "move", {"x":flag.pos.x,"y":flag.pos.y})
commandFriends()
hero.cast("invisibility", hero)
hero.moveXY(52, 15)
target = hero.findNearestEnemy()
hero.cast("chain-lightning", target)
while True:
    commandFriends()
    commandCaptain()

by the way, I have the Twilight glasses, so I can see after the walls.

1 Like

Well, I try to avoid using flags if at all possible, so not sure if I can help there. Instead, I used hero.now() and commanded them to move to specific locations at specific times.

@Deadpool198 is it even possible to have a friend retrieve a flag?

Well, they might not be able to retrieve it, as in remove it. But they could move to its location. Then you could you flag.remove? It’s something like that you get with the most advanced flag.
I also used hero.now() (well, I used hero.time(), but they’re exactly the same). You might want to consider that.

How do you use hero.now()? I never used it before

1 Like

You could use hero.time(), it’s the same.

1 Like