Please Help me on Kelvintaph Crusader

# You can find friends through walls, but not enemies.
# Watch out for smooth, frictionless ice patches!

enemy = hero.findNearestEnemy()
hero.cast("chain-lightning", enemy)
# def lowestHealthSoldier():
#     lowestSoldier = False
#     lowestHealth = 9999
#     soldiers = hero.findByType("soldiers")
#     for soldier in soldiers:
#         if soldier.health < lowestHealth:
#             lowestHealth = soldier.health
#             lowestSoldier = soldier
#     return lowestSoldier


def commandPaladin(paladin):
    witch = paladin.findNearest(hero.findByType('witch'))
    enemy = paladin.findNearest(hero.findEnemies())
    
    if witch and witch.health > 0:
        hero.command(paladin, "attack", witch)
    elif enemy:
        hero.command(paladin, "attack", enemy)
    if paladin.canCast('heal'):
        hero.command(paladin, "cast", 'heal', paladin)
    


def commandSoldier(soldier):
    enemy = soldier.findNearestEnemy()
    if enemy:
        hero.command(soldier, "attack", enemy)


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

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

def commandHero():
    catapult = hero.findNearest(hero.findByType("catapult"))
    enemy = hero.findNearestEnemy()
    
    if catapult:
        hero.attack(catapult)
    elif enemy:
        hero.attack(enemy)

while True:
    commandTroops()
    commandHero()

What is wrong with my code? My friends/units are stuck once in a while. Why did that happen? Can someone tell me please. Thank!

Screen Shot 2020-04-25 at 1.12.38 PM here is what I wear

and I am using okar stomp foot

You are missing the exit strategy…you need to get both your hero and friends to the Xs on the east side of the map.

I know that, but all of my friends died before the ogres are killed

Well, you can take out the south guys with the catapults…your friends can outrun the others; only the witch needs to be killed, actually.

I know I can just add

noEnemy = not (hero.findNearestEnemy)
if noEnemy:
    #move to the exit

oh thanks
(20 chars)

But then I can’t get the bonus

True, if not all friends escape. Think paladin (heal) and archer (range), others run like heck once the witch is down…it is possible.
image

I got it!!! I made some adjustments and my friends killed everything! I just used flags in the end to make sure that nobody dies by the trap.

1 Like

They are all surviving!!

WOOT!!! (Yes, it’s a complete sentence!)