Kelvintaph crusader help!

The only problem I have, is that none of my allies get to the point.
My code:

# Вы можете находить друзей сквозь стены. Но не врагов.
# Берегитесь гладких, скользких ледяных участков!
while True:
    def lowestHealthFriend():
        lowestHealth = 99999
        lowestFriend = None
        friends = hero.findFriends()
        friends.append(hero.findByType('paladin')[0])
        for friend in friends:
            if friend.health < lowestHealth and friend.health < friend.maxHealth:
                lowestHealth = friend.health
                lowestFriend = friend
        return lowestFriend
    flag = hero.findFlag("green")
    enemy = hero.findNearestEnemy()
    if flag:
        if hero.isReady("blink"):
            hero.blink(flag.pos)
            hero.pickUpFlag(flag)
        else:
            hero.pickUpFlag(flag)
    else:
        if enemy:
            if hero.isReady("throw") and hero.distanceTo(enemy.pos) < hero.throwRange:
                hero.throw(enemy)
            elif hero.isReady("shadow-vortex"):
                hero.shadowVortex(hero.pos, {"x": 74, "y": 15})
            elif hero.isReady("wall-of-darkness"):
                hero.wallOfDarkness([{"x": 22, "y": 24}, {"x": 22, "y": 5}]);
            elif hero.canCast("chain-lightning", enemy):
                hero.cast("chain-lightning", enemy)
            else:
                hero.attack(enemy)
    friends = hero.findFriends()
    for friend in friends:
        enemy = friend.findNearestEnemy()
        if friend.type != 'paladin':
            if enemy and enemy.type == 'witch':
                hero.command(friend, "attack", enemy)
            else:
                hero.command(friend, "move", {'x': 50, 'y': 58})
                hero.command(friend, "move", {'x': 49, 'y': 38})
                hero.command(friend, "move", {'x': 78, 'y': 40})
        else:
            lowestFriend = lowestHealthFriend()
            paladin = hero.findByType("paladin")[0]
            if lowestFriend and paladin.canCast("heal"):
                hero.command(paladin, "cast", "heal", lowestFriend)
            elif enemy and enemy.type == 'witch':
                hero.command(friend, "attack", enemy)
            else:
                hero.command(friend, "move", {'x': 50, 'y': 58})
                hero.command(friend, "move", {'x': 49, 'y': 38})
                hero.command(friend, "move", {'x': 78, 'y': 40})

My equipment:

do you need ritic to complete this level

What do you mean ‘need’?Yes, Ritic will defend himself perfectly.But if needed, I can try with another hero.

Is he required in Dlvintaph crusader

As I told you in the previos post:

What I think @milton.jinich is saying is you don’t need Ritic to complete the level

okay thanks for clearing things up @CryptiCrystal

1 Like

Ok.What should I do?

Hi Anonym,

This is quite a hard level - it took me a lot of goes.

Ritic is fine, and you use his skills to solve the bottom half of the problem.

Move the whole function def lowestHealthFriend() outside the while True loop (you still call it from inside the loop, so it’ll still run).

For the top half, I used the archers to kill the witch, and the paladin to draw the skeletons away so all the allies could escape.

For commanding the friends to move, I think if you give all three “move” commands to different places at the same time then just one of them will run.

Good luck.

Jenny

3 Likes

Thanks a lot, @jka2706!I’ll try these actions. :clap:

Ok, I tried to use your instructions:

# Вы можете находить друзей сквозь стены. Но не врагов.
# Берегитесь гладких, скользких ледяных участков!
def lowestHealthFriend():
    lowestHealth = 99999
    lowestFriend = None
    friends = hero.findFriends()
    friends.append(hero.findByType('paladin')[0])
    for friend in friends:
        if friend.health < lowestHealth and friend.health < friend.maxHealth:
            lowestHealth = friend.health
            lowestFriend = friend
    return lowestFriend
while True:
    flag = hero.findFlag("green")
    enemy = hero.findNearestEnemy()
    if flag:
        if hero.isReady("blink"):
            hero.blink(flag.pos)
            hero.pickUpFlag(flag)
        else:
            hero.pickUpFlag(flag)
    else:
        if enemy:
            if hero.isReady("throw") and hero.distanceTo(enemy.pos) < hero.throwRange:
                hero.throw(enemy)
            elif hero.isReady("shadow-vortex"):
                hero.shadowVortex(hero.pos, {"x": 74, "y": 15})
            elif hero.isReady("wall-of-darkness"):
                hero.wallOfDarkness([{"x": 22, "y": 24}, {"x": 22, "y": 5}]);
            elif hero.canCast("chain-lightning", enemy) and enemy.type == 'witch':
                hero.cast("chain-lightning", enemy)
            else:
                hero.attack(enemy)
    friends = hero.findFriends()
    for friend in friends:
        enemy = friend.findNearestEnemy()
        if friend.type == 'archer':
            if enemy.type == 'witch':
                hero.command(friend, "attack", enemy)
            hero.command(friend, "move", {'x': 31, 'y': 58})
            hero.command(friend, "move", {'x': 49, 'y': 58})
        elif friend.type == 'paladin':
            """
            lowestFriend = lowestHealthFriend()
            if lowestFriend and friend.canCast('heal'):
                friend.cast('heal')
            """
            if enemy.type == 'skeleton':
                hero.command(friend, "attack", enemy)
            hero.command(friend, "move", {'x': 31, 'y': 58})
            hero.command(friend, "move", {'x': 49, 'y': 58})
        elif friend.type == 'soldier':
            if enemy.type == 'ogre':
                hero.command(friend, "attack", enemy)
            hero.command(friend, "move", {'x': 31, 'y': 58})
            hero.command(friend, "move", {'x': 49, 'y': 58})

However, my friends keep dying.

OK, you’re far enough through CoCo now that to some extent you’re going to have to solve the problems by yourself - you’ll learn by trying things to see if they work, even if it’s frustrating. Each time you change the code, run it to see what happens and whether that was what you wanted. It’s a skill you’ll keep needing as you get better at coding!

One thing from your code - you still have the hero command move statements in pairs, so they won’t work as you want them to - you’ll have to separate them and write code to say which one happens when.

Jenny

Here is my code:

# Вы можете находить друзей сквозь стены. Но не врагов.
# Берегитесь гладких, скользких ледяных участков!
def lowestHealthFriend():
    lowestHealth = 99999
    lowestFriend = None
    friends = hero.findFriends()
    friends.append(hero.findByType('paladin')[0])
    for friend in friends:
        if friend.health < lowestHealth and friend.health < friend.maxHealth:
            lowestHealth = friend.health
            lowestFriend = friend
    return lowestFriend
while True:
    flag = hero.findFlag("green")
    enemy = hero.findNearestEnemy()
    if flag:
        if hero.isReady("blink"):
            hero.blink(flag.pos)
            hero.pickUpFlag(flag)
        else:
            hero.pickUpFlag(flag)
    else:
        if enemy:
            if hero.isReady("throw") and hero.distanceTo(enemy.pos) < hero.throwRange:
                hero.throw(enemy)
            elif hero.isReady("shadow-vortex"):
                hero.shadowVortex(hero.pos, {"x": 74, "y": 15})
            elif hero.isReady("wall-of-darkness"):
                hero.wallOfDarkness([{"x": 22, "y": 24}, {"x": 22, "y": 5}]);
            elif hero.canCast("chain-lightning", enemy) and enemy.type == 'witch':
                hero.cast("chain-lightning", enemy)
            else:
                hero.attack(enemy)
    friends = hero.findFriends()
    for friend in friends:
        enemy = friend.findNearestEnemy()
        if friend.type == 'archer':
            if enemy.type == 'witch':
                hero.command(friend, "attack", enemy)
            else:
                if friend.pos != {'x': 31, 'y': 58}:
                    hero.command(friend, "move", {'x': 31, 'y': 58})
                else:
                    hero.command(friend, "move", {'x': 49, 'y': 58})
        elif friend.type == 'paladin':
            lowestFriend = lowestHealthFriend()
            if lowestFriend and hero.findByType("paladin")[0].canCast('heal'):
                friend.cast('heal')
            if enemy.type == 'witch':
                hero.command(friend, "attack", enemy)
            else:
                if friend.pos != {'x': 31, 'y': 58}:
                    hero.command(friend, "move", {'x': 31, 'y': 58})
                else:
                    hero.command(friend, "move", {'x': 49, 'y': 58})
        elif friend.type == 'soldier':
            if enemy.type == 'witch':
                hero.command(friend, "attack", enemy)
            else:
                if friend.pos != {'x': 31, 'y': 58}:
                    hero.command(friend, "move", {'x': 31, 'y': 58})
                else:
                    hero.command(friend, "move", {'x': 49, 'y': 58})

I don’t actually know, why my friends keep dying.The witch kills them.
@jka2706, I come to this forum when I can’t find any ideas.I passed many levels by myself.But some levels are too difficult.That’s why I can’t solve them myself.

The answers you are looking for are given many times in the forum. In addition, there is a video that shows a possible strategy for passing the level.

Sometimes it’s good idea to start from the blank page.
I complete this level with strategy based on time-depending functions to command allies and hero. Not the perfect variant I think. But I would maybe suggest you to use the same tactics.
And xython is right, searching the forum for this level related topics may help also.