Kelvintaph Glacier defiler strategy problem

same i can’t beat it either

How do you kill the warlocks?

Nalfar will kill them. Once he loses enough health (archers and soldiers should attack him), he’ll cast swap with the yeti, then cast fireball and kill the warlocks, before running off.

1 Like

My paladin attacked him, and also used heal when health became half.

2 Likes
hero.moveXY(33, 23)

paladin = getPaladin()
enemy = paladin.findNearest([e for e in hero.findEnemies() if [e.id ](http://e.id) is “ULD’MAK”])
if enemy:
friends = self.findFriends()
for friend in friends:
hero.command(friend, “attack”, enemy)

while True:
commandPaladin(getPaladin())

def commandPaladin(paladin):
# Heal the paladin with the lowest health using lowestHealthPaladin()
# You can use paladin.canCast(“heal”) and command(paladin, “cast”, “heal”, target)
# Paladins can also shield: command(paladin, “shield”)
# And don’t forget, they can attack, too!
# self.command(paladin, “shield”)
if paladin:
if paladin.canCast(“heal”):
self.command(paladin, “cast”, “heal”, paladin)
else:
self.command(paladin, “shield”)

def getPaladin():
paladin = None
friends = self.findFriends()
for friend in friends:
if friend.type == “paladin”:
paladin = friend
continue


return paladin
```[quote="safe751129, post:19, topic:10243, full:true"]
My code is:
# The ogres are trapping you with their dark rituals!
# Your hero can't do anything besides command and move without angering the warlocks.
# Beware ice, robots, traps, antigravity fields, and other dark magic.
# Somehow, you'll need to defeat Nalfar and save your paladin.
# The great treasure of Kelvintaph awaits your victory.
hero.moveXY(33, 23)

paladin = getPaladin()
enemy = paladin.findNearest([e for e in hero.findEnemies() if e.id is "ULD'MAK"])
if enemy:
    friends = self.findFriends()
    for friend in friends:
        hero.command(friend, "attack", enemy)
      
while True:
    commandPaladin(getPaladin())


def commandPaladin(paladin):
    # Heal the paladin with the lowest health using lowestHealthPaladin()
    # You can use paladin.canCast("heal") and command(paladin, "cast", "heal", target)
    # Paladins can also shield: command(paladin, "shield")
    # And don't forget, they can attack, too!
    # self.command(paladin, "shield")
    if paladin:
        if paladin.canCast("heal"):
            self.command(paladin, "cast", "heal", paladin)
        else:
            self.command(paladin, "shield")


def getPaladin():
    paladin = None
    friends = self.findFriends()
    for friend in friends:
        if friend.type == "paladin":
            paladin = friend
            continue
        
    return paladin

I can get my paladin to shield and heal, but I don't get why my troops are not attacking the ogres.

eeeeee
ereeeeeeee
[/quote]

[quote="safe751129, post:19, topic:10243"]
hero.moveXY(33, 23)

paladin = getPaladin()
enemy = paladin.findNearest([e for e in hero.findEnemies() if [e.id ](http://e.id) is “ULD’MAK”])
if enemy:
friends = self.findFriends()
for friend in friends:
hero.command(friend, “attack”, enemy)

while True:
commandPaladin(getPaladin())

def commandPaladin(paladin):
# Heal the paladin with the lowest health using lowestHealthPaladin()
# You can use paladin.canCast(“heal”) and command(paladin, “cast”, “heal”, target)
# Paladins can also shield: command(paladin, “shield”)
# And don’t forget, they can attack, too!
# self.command(paladin, “shield”)
if paladin:
if paladin.canCast(“heal”):
self.command(paladin, “cast”, “heal”, paladin)
else:
self.command(paladin, “shield”)

def getPaladin():
paladin = None
friends = self.findFriends()
for friend in friends:
if friend.type == “paladin”:
paladin = friend
continue
[/quote]

Hi, do you need help with your code?
Please could you explain what you mean with that post.
Thanks
Danny

this is my code.

def isLater(units,testUnit):
    if units[len(units)-1]==testUnit:
        return True
    else:
        return
def codeUnits():
    fs=hero.findFriends()
    es=hero.findEnemies()
    
    
    
    for target in es:
        for f in fs: 
            
            isLater2=isLater(fs,f)
            if isLater2 and f.type!='paladin' and target.id!='drun' and target.id!='gror' and target.type=='shaman':
                hero.command(f, "attack", target)            
                x=22
                y=56
                if f.type=='archer':
                    hero.command(f, "move", {'x':x,'y':y})
            if f.type!='paladin':
                hero.command(f, "attack", target)
            
def herosystem():
    step={'x':33, 'y':6}
    paladin=hero.findByType("paladin")[0]
    if paladin.health<600:
        hero.command(paladin, "shield")
    hero.move(step)
herosystem()
while True:
    codeUnits()

Hi @txt_art, I presume you need help with this level. Please could you describe what’s happening when you run the code.
I also don’t think you have quite enough code for this level. Maybe try a step system based on hero.time to help divide the level into chunks.
Danny

1 Like

As @Deadpool198 said, try to use a step system that tells you in what part of the code are you, that can be based on time, flags, different enemies existing and many more (the best way is with hero.time()).

Andrei

HEY @Deadpool198 I SENT YOU A MESSAGE REAGRADING KELVINTAPH CRUSADER AND WHY DIDN"T YOU RESPOND!! I know you are a very good coder and have jobs to do but can you make atleast 30 minutes of time for me in your day… PLEASE!!! pleading_face:

Hi goutha123, please understand that some people are in different time zones, so they might not see your message until later. What you can do is post your code and ask for help
Lydia

@Lydia_Song I have waited a whole week, for the solutions but I didn’t get any reply

If you ask him for the derect solution he won’t give it to you.

And please just dont revive dead topics.

If you ask for a solution directly, no one is going to give it to you since it is against the rules and it is not the purpose of CodeCombat. If you just copy and paste it in, you won’t learn anything. How about you try the level and post your code here if you have any problems?
Lydia

if hero.canCast("chain-lightning", "Trogdor"):
    hero.cast("chain-lightning", "Trogdor")

while True:
    friends = hero.findFriends()
    paladins = hero.findByType("paladin")
    enemies = hero.findEnemies()
    witches = hero.findByType("witch")
    enemies = hero.findEnemies()
    ogre = hero.findByType("ogre", hero.findEnemies())
    for friend in friends:
        if friend.type != 'paladin':
            if ogre.health > 0:
                hero.command(friend, "attack", "Oni")
            elif ogre.health <= 0:
                if friend.type == 'paladin':
                    hero.command(friend, "shield")
                elif 'Rusty' :
                    hero.command(friend, "attack", "Rusty")
                elif 'Skully':
                    hero.command(friend, "attack", "Skully")
        
        elif friend.type == 'paladin':
            if friend.health <= 300:
                hero.command(friend, "shield")
            else:
                witch = 'Yzzrith'
                hero.command(friend, "attack", witch)
    for enemy in enemies:
        if enemy.type is "catapult":
            while enemy.health > 0:
                hero.attack(enemy) 
            hero.moveXY(78, 14)
            enemies = hero.findEnemies()

This is my new code, my paladin is not shielding when asked. and he is not healing himself, so far I made some progress in the code, please feel free to try it out…

This is the problem with the level, can you please help me out

The problem is that my paladin is not shielding nor healing himself.

Hi goutham123,

Only just noticed that you don’t have any replies.

Have a look at these lines here:

        if friend.type != 'paladin':
            if ogre.health > 0:
                hero.command(friend, "attack", "Oni")
            elif ogre.health <= 0:
                if friend.type == 'paladin':
                    hero.command(friend, "shield")

If the friend is a paladin, it will get to the first of these lines, and the if statement will be false. At that point the code will jump over all of the following lines, so the lines about the paladin shielding will never run.

How about just write it as:
if friend.type != 'paladin':
and then
else:
for the code for the paladins?

Jenny

@jka2706 THANK YOU SO MUCH!!! I AM SO GRATEFUL… IT WORKED!! The paladin is shielding, he is healing, and everything is going to plan. Could you please help me in how to move my allies onto the X.

with Thanks,
goutham123

1 Like