Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

HELP Kelvintaph Crusader

Well, so I searched and reviewed a lot in the forum and many people had problems with this level and I am one of them. My code has no error, it just never ends and it gets stuck. Can someone help me?

# You can find friends through walls, but not enemies.
# Watch out for smooth, frictionless ice patches!
def command():
    friends = hero.findFriends()
    for friend in friends:
        witch = hero.findByType("witch",friends[0].findEnemies())[0]
        if witch and witch.health>0:
            if friend.type=="paladin" or friend.type=="archer":
                hero.command(friend,"attack",witch)
            elif friend.type=="soldier":
                ogre = hero.findByType("ogre",friend.findEnemies())
                if ogre:
                    hero.command(friend,"attack",ogre[0])
            if friend.type=="paladin":
                if friend.canCast("heal") and friend.health<300:
                    hero.command(friend,"cast","heal",friend)
        else:
            enemy=friend.findNearestEnemy()
            if enemy:
                hero.command(friend,"attack",enemy)
            else:
                point2 = { "x" : 61, "y" : 57 }
                while hero.distanceTo( point2 ) > 1:
                    hero.command(friend,"move",point2)
                point2 = { "x" : 78, "y" : 40 }
                while hero.distanceTo( point2 ) > 1:
                    hero.command(friend,"move",point2)
                
            
            if friend.type=="paladin":
                if friend.canCast("heal") and friend.health<300:
                    hero.command(friend,"cast","heal",friend)
    
    
while True:
    command()
    enemy = hero.findNearest(hero.findEnemies())
    if "Trogdor":
        hero.cast( "chain-lightning", "Trogdor" )
    else:
        hero.cast( "chain-lightning", "Rusty" )
    point1 = { "x" : 69, "y" : 15 }
    point2 = { "x" : 37, "y" : 16 }
    while hero.pos.x<69:
        command()
        hero.move( point1 )
    while hero.pos.x>37:
        command()
        hero.move( point2 )
    for i in range(3):
        enemy = hero.findNearest(hero.findByType("catapult"))
        if enemy:
            hero.attack(enemy)
            
    point3 = { "x" : 37, "y" : 16 }
    point4 = { "x" : 78, "y" : 14 }
    while hero.pos.x>37:
        command()
        hero.move( point3 )
    while hero.pos.x<78:
        command()
        hero.move( point4 )

Your hero can not find enemies that are on the other side of the wall.

If you want to find the witch, you should use:

friends = hero.findFriends()
friend = friends[0]
enemies =friend.findEnemies()

and search for the witch in the enemies array, so you just check every enemy if their type is “witch”.

And you should check after you call the command() function in the while True loop if your hero can cast chain lightning like this:

    if hero.canCast("chain-lightning"):
        #insert your spell code here.  
    else: #insert your normal attack code or move code here.

You get stuck because your hero waits for the spell to be used again, so your whole code stops while he does that.

So this is my code now, the code is not stuck anymore and dosent have any errors but my allies die

Then try to think at a different tactic

Can i see your equipment? because i just beat this level and bonus as well. Kinda hard, i only got the bonus with mage equipment

i also recommend you buy the twilight glasses so that you can see through walls

Thats weird
this is my equipment

Well try to fix the code to pass the level but I just did worse what is wrong with this code

# You can find friends through walls, but not enemies.
# Watch out for smooth, frictionless ice patches!
def command():
    friends = hero.findFriends()
    for friend in friends:
        witch = hero.findByType("witch",friends[0].findEnemies())[0]
        if witch and witch.health>0:
            if friend.type=="paladin" or friend.type=="archer":
                hero.command(friend,"attack",witch)
        elif friend.type=="soldier":
            ogre = hero.findByType("ogre",friend.findEnemies())
            if ogre:
                hero.command(friend,"attack", ogre[0])  
        if friend.type=="paladin":
            if friend.canCast("heal") and friend.health<300:
                hero.command(friend,"cast","heal",friend)
        else:
            enemy=friend.findNearestEnemy()
            if enemy:
                hero.command(friend,"attack",enemy)
            else:
                point2 = { "x" : 61, "y" : 57 }
                while hero.distanceTo( point2 ) > 1:
                    hero.command(friend,"move",point2)
                point2 = { "x" : 78, "y" : 40 }
                while hero.distanceTo( point2 ) > 1:
                    hero.command(friend,"move",point2)
                
            
            if friend.type=="paladin":
                if friend.canCast("heal") and friend.health<300:
                    hero.command(friend,"cast","heal",friend)
    
    
while True:
    command()
    enemy = hero.findNearest(hero.findEnemies())
    if "Trogdor":
        hero.cast( "chain-lightning", "Trogdor" )
    point1 = { "x" : 69, "y" : 15 }
    point2 = { "x" : 37, "y" : 16 }
    while hero.pos.x<69:
        command()
        hero.move( point1 )
    while hero.pos.x>37:
        command()
        hero.move( point2 )
    for i in range(3):
        enemy = hero.findNearest(hero.findByType("catapult"))
        if enemy:
            hero.attack(enemy)
            
    point3 = { "x" : 37, "y" : 16 }
    point4 = { "x" : 78, "y" : 14 }
    while hero.pos.x>37:
        command()
        hero.move( point3 )
    while hero.pos.x<78:
        command()
        hero.move( point4 )

This is the error

I’ll put some tips here and there. (I use JavaScript so bear with me here.)

# You can find friends through walls, but not enemies.
# Watch out for smooth, frictionless ice patches!
def command():
    friends = hero.findFriends()
    for friend in friends:
        witch = hero.findByType("witch",friends[0].findEnemies())[0]
        if witch and witch.health>0:
            if friend.type=="paladin" or friend.type=="archer":
                hero.command(friend,"attack",witch)
        elif friend.type=="soldier":
            ogre = hero.findByType("ogre",friend.findEnemies()) # you didn't add [0] like you did with the witch.
            if ogre:
                hero.command(friend,"attack", ogre[0])  
        if friend.type=="paladin":
            if friend.canCast("heal") and friend.health<300: # make sure the paladin doesn't heal the hero (use if not hero)
                hero.command(friend,"cast","heal",friend)
        else:
            enemy=friend.findNearestEnemy()
            if enemy:
                hero.command(friend,"attack",enemy)
            else:
                point2 = { "x" : 61, "y" : 57 }
                while hero.distanceTo( point2 ) > 1:
                    hero.command(friend,"move",point2) # move the point above the move command
                point2 = { "x" : 78, "y" : 40 } # change this to point3 so that it's more organized
                while hero.distanceTo( point2 ) > 1:
                    hero.command(friend,"move",point2) 
                
            
            if friend.type=="paladin":
                if friend.canCast("heal") and friend.health<300:
                    hero.command(friend,"cast","heal",friend)
    
    
while True:
    command()
    enemy = hero.findNearest(hero.findEnemies())
    if "Trogdor":
        hero.cast( "chain-lightning", "Trogdor" ) # this is not required
    point1 = { "x" : 69, "y" : 15 } 
    point2 = { "x" : 37, "y" : 16 }
    while hero.pos.x<69:
        command()
        hero.move( point1 )
    while hero.pos.x>37:
        command()
        hero.move( point2 )
    for i in range(3):
        enemy = hero.findNearest(hero.findByType("catapult"))
        if enemy:
            hero.attack(enemy)
            
    point3 = { "x" : 37, "y" : 16 }
    point4 = { "x" : 78, "y" : 14 }
    while hero.pos.x>37:
        command()
        hero.move( point3 )
    while hero.pos.x<78:
        command()
        hero.move( point4 )

You put some unnecessary code in the hero move part. you only need to move your hero to the center (the snowy patch, wait for the catapult to fire there, move away, move to the catapults and wait for them to fire again, move away, and escape. It’s easier to do the move command when it’s tied to time instead of position. and make sure you command them every time you move

P.S: with your current equipment, it’s almost impossible to get the bonus. but you only need to defeat the witch to open the gate, so defeat the witch, and just escape, since the enemies are slower than you.

Never mind i fixed that now but my friends get stuck at one point can u help me

# You can find friends through walls, but not enemies.
# Watch out for smooth, frictionless ice patches!
def command():
    friends = hero.findFriends()
    for friend in friends:
        witch = hero.findByType("witch",friends[0].findEnemies())[0]
        if witch and witch.health>0:
            if friend.type=="paladin" or friend.type=="archer":
                hero.command(friend,"attack",witch)
            else:
                pass
                
        if friend.type=="soldier":
            ogre = hero.findByType("ogre",friends[0].findEnemies())[0]
            if ogre:
                hero.command(friend,"attack", ogre) 
                if enemy:
                    enemy = hero.findNearestEnemy()
                    hero.command(friend, "attack", enemy)
                else:
                    pass
                
        if friend.type=="paladin":
            if friend.canCast("heal") and friend.health<300:
                hero.command(friend,"cast","heal",friend)
            else:
                enemy=friend.findNearestEnemy()
                if enemy:
                    hero.command(friend,"attack",enemy)
                    
                else:
                    point1 = { "x" : 61, "y" : 57 }
                    hero.command(friend,"move",point1)
                    point2 = { "x" : 78, "y" : 40 }
                    hero.command(friend,"move",point2)
                

while True:
    command()
    enemy = hero.findNearest(hero.findEnemies())
    if "Trogdor":
        hero.cast( "chain-lightning", "Trogdor" )
    else:
        while True:
            hero.move({"x": 41, "y": 14})
            hero.wait(1)
            hero.move({"x": 78, "y": 14})
            hero.wait(1)
            pass
    for i in range(3):
        enemy = hero.findNearest(hero.findByType("catapult"))
        if enemy:
            hero.attack(enemy)
            

any if “non empty string” will be always True

    if "Trogdor": # fault
        hero.cast( "chain-lightning", "Trogdor" )
# replace with 
    enemy = hero.findNearest(hero.findEnemies())
    if enemy and hero.isReady( "chain-lightning"):
        hero.cast( "chain-lightning", enemy ) # Trogdor is the nearest enemy

You can command any of your friend individually after naming them and all your enemies
Naming the enemies ( can be done outside the while loop):

enemies= hero.findEnemies()
for enemy in enemies:
    if enemy.id == "Oni":
        oni = enemy
    elif enemy.id == "Trogdor":
        trogdor = enemy
    elif enemy.id == "Rusty":
        rusty = enemy
    elif enemy.id == "Skully":
        skully = enemy
    elif enemy.id == "Yzzrith":
        yzzrith = enemy

then name your friends…
The biggest problem is moving your hero:

                point2 = { "x" : 61, "y" : 57 }
                while hero.distanceTo( point2 ) > 1:
                    hero.command(friend,"move",point2) # move the point above the move command
                point2 = { "x" : 78, "y" : 40 } # change this to point3 so that it's more organized
                while hero.distanceTo( point2 ) > 1:
                    hero.command(friend,"move",point2) 
########################################################
    point1 = { "x" : 69, "y" : 15 } 
    point2 = { "x" : 37, "y" : 16 }
    while hero.pos.x<69:
        command()
        hero.move( point1 )
    while hero.pos.x>37:
        command()
        hero.move( point2 )
######################################################           
    point3 = { "x" : 37, "y" : 16 }
    point4 = { "x" : 78, "y" : 14 }
    while hero.pos.x>37:
        command()
        hero.move( point3 )
    while hero.pos.x<78:
        command()
        hero.move( point4 )

These commands will maybe freeze your browser… The updated move code will also fail.
I don’t like nested loops but modified your idea to work somehow:

point1 = { "x" : 110, "y" : 30 }
point2 = { "x" : 120, "y" : 100 }
point3 = { "x" : 80, "y" : 70 }
n=0
while n < 1:
    while hero.distanceTo(point1) >= 0:
        if  hero.distanceTo(point1) > 0:
            if hero.gold >= hero.costOf("paladin") and hero.pos.x > 90:
                hero.summon("paladin")
            hero.move( point1 )
        else:
            break
    while hero.distanceTo(point2) >= 0:
        if  hero.distanceTo(point2) > 0:
            if hero.gold >= hero.costOf("archer") and hero.pos.x > 115:
                hero.summon("archer")
            hero.move( point2 )
        else:
            break
    while hero.distanceTo(point3) >= 0:
        if  hero.distanceTo(point3) > 0:
            if hero.gold >= hero.costOf("soldier") and hero.pos.x < 100:
                hero.summon("soldier")
            hero.move( point3 )
        else:
            break
    n +=1

Put your command() function at the lines where the hero summons minions.
See the test video of the above code: Triangle with summons
I use similar idea to move the hero and the minions but without nested loops:
See the video of the solved level: Kelvintaph Crusader
/ no code - sorry :slight_smile: /

for the move command, use a for loop to iterate over your friends and command them to move

I’ll put up some sample code for you to follow, it’s in javascript though since i use this language.

I’ll explain a little about this code

 if (friend) {  # This checks for friends, change it to friend.type
                 if (friend.pos.x < 47) {  # this checks the x position of friends
                      hero.command(friend, "move", {x : 50, y: 59}); # the first moving point. only move if they are on the left side of the area
                 } else if (friend.pos.y > 42){ # this checks the y position of friends
                    hero.command(friend, "move", {x : 50, y: 39});  # the second moving point. only move to this point after they moved to the first point (Hence the elif code)
                 } else { # the positions are set
                     hero.command(friend, "move", {x : 78, y: 40}); # the third point, aka the exit. only move after the other points
                 }
            }

Also, remove the chain lightning command, and fix the heroMove function. It’s better if you assign the positions you need to move to using hero.time, as you can align the cannon fire to your position. Once the code runs, immediately run to the center of the map. then move away, run to the cannons, and move away. This will kill the brawlers and cannons at two different intervals.

use something like this

var time = hero.time;
 if (time < ???) {
        hero.moveXY(???);
    }
    else if (time > ??? && time < ???) {
        hero.moveXY(???);
    }

we use moveXY here since you have to move immediately to that position instead of counting steps, therefore the code does not mess up the alignments of the cannon

P.S : flags and hero weapons are not required here. i recommend the ring of speed for an added bonus speed.

hope this helps
Riley

@Valentino_Artawan
I cannot understand how do you command your minions during the movement with moveXY (). Curious to see a video of your solution - can you post it?

Simple. I put the command function in between movements. Since the function takes less than half a second to do, this won’t mess up the movement. and It’s a good way of making sure your friends walk to your command before moving again

Hang on I’ll need to find a way to submit the video to you

Here’s the video (Ignore the code, it’s just a move code)

Kelvintaph Crusader : Mage Class

P.S: This will probably solve the whole level. so please make sure you understand what you coded before plagiarizing my code. thanks

Riley

I see in the video you use the fireball to destoy the catapult by using wait
Thanks for the help ill try your method and see if it works

Thank you very much for the code but I really want to pass the level with my strategy

@Valentino_Artawan
Thank you for sharing the video!
I understand your method. Maybe for someone your solution will be easier than mine.
@Ry4n_17
I didn’t use anywhere hero. waits or hero. time in my code. The hero type doesn’t matter and the code will work with all warriors and even in any surroundings. I can only change the minions movement array and the hero movement array to solve another similar level.

Same. since the movement of my hero depends on the time, it’s completely independent on the top half of the level or any manual flag placing. (Trust me, that extra hero support function to support my troops were necessary to get the bonus)