# Kelvintaph Crusader Help Codecombat

**URL:** <https://discourse.codecombat.com/t/kelvintaph-crusader-help-codecombat/25660>\
**Category:** Level Help\
**Created:** [November 24, 2020, 6:36pm UTC](https://discourse.codecombat.com/t/kelvintaph-crusader-help-codecombat/25660 "2020-11-24T18:36:29Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![CryptiCrystal](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/crypticrystal/32/16228_2.png) [@CryptiCrystal](https://discourse.codecombat.com/u/CryptiCrystal)\
**Post date:** [November 24, 2020, 6:36pm UTC](https://discourse.codecombat.com/t/kelvintaph-crusader-help-codecombat/25660/1 "2020-11-24T18:36:29Z")

</div>

> **Code**
>
> ```python
> while True:
> command()
> move()
> def command():
> friends = hero.findFriends()
> witches = hero.findByType("witch")
> targets = hero.findEnemies()
> for witch in witches:
> for friend in friends:
> for target in targets:
> if witch:
> hero.command(friend, "attack", witch)
> elif target.type != "brawler" and target.health > 0:
> hero.command(friend, "attack", target)
> def move():
> hero.moveXY(69, 14)
> hero.wait(2)
> hero.moveXY(15, 14)
> 
> ```

> **Link**
>
> [https://codecombat.com/play/level/kelvintaph-crusader](https://codecombat.com/play/level/kelvintaph-crusader)

My code runs like this. I move to make the catapults kill the brawlers and themselves, but after my troops kill the witch, they just stop attacking. Help?

---

<div class="post-metadata">

**Author:** ![Deadpool198](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/deadpool198/32/16753_2.png) [@Deadpool198](https://discourse.codecombat.com/u/Deadpool198)\
**Post date:** [November 24, 2020, 6:52pm UTC](https://discourse.codecombat.com/t/kelvintaph-crusader-help-codecombat/25660/2 "2020-11-24T18:52:43Z")

</div>

> [@CryptiCrystal](#):
>
> ```python
> for witch in witches:
> for friend in friends:
> for target in targets:
> if witch:
> hero.command(friend, "attack", witch)
> elif target.type != "brawler" and target.health > 0:
> hero.command(friend, "attack", target)
> 
> ```

This is quite a confusing structure. A triple for loop will not work very well.  
Remember that the second and third for loops will only run when the first for loop runs. The first for loop will only run when there are witches. So if there are no witches will it run?  
Danny

---

<div class="post-metadata">

**Author:** ![CryptiCrystal](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/crypticrystal/32/16228_2.png) [@CryptiCrystal](https://discourse.codecombat.com/u/CryptiCrystal)\
**Post date:** [November 30, 2020, 4:48pm UTC](https://discourse.codecombat.com/t/kelvintaph-crusader-help-codecombat/25660/3 "2020-11-30T16:48:29Z")

</div>

Hmmmm, I never thought about that. Now that I’ve changed my code, it does the same thing. The troops kill the witch and then just stand still. Here it is.

```python
while True:
    command()
    move()
def command():
    friends = hero.findFriends()
    witch = hero.findNearest(hero.findByType("witch"))
    for friend in friends:
        enemy = friend.findNearestEnemy()
        if witch:
            hero.command(friend, "attack", witch)
        elif enemy.type != "witch":
            hero.command(friend, "attack", enemy)
def move():
    hero.moveXY(69, 14)
    hero.wait(2)
    hero.moveXY(15, 14)

```

---

<div class="post-metadata">

**Author:** ![cheddarcheese](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/cheddarcheese/32/22417_2.png) [@cheddarcheese](https://discourse.codecombat.com/u/cheddarcheese)\
**Post date:** [November 30, 2020, 5:10pm UTC](https://discourse.codecombat.com/t/kelvintaph-crusader-help-codecombat/25660/4 "2020-11-30T17:10:46Z")

</div>

try changing the elif to an if

---

<div class="post-metadata">

**Author:** ![CryptiCrystal](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/crypticrystal/32/16228_2.png) [@CryptiCrystal](https://discourse.codecombat.com/u/CryptiCrystal)\
**Post date:** [November 30, 2020, 5:13pm UTC](https://discourse.codecombat.com/t/kelvintaph-crusader-help-codecombat/25660/5 "2020-11-30T17:13:07Z")

</div>

Nope. It then just targets the nearest enemy and not the witch.

---

<div class="post-metadata">

**Author:** ![CryptiCrystal](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/crypticrystal/32/16228_2.png) [@CryptiCrystal](https://discourse.codecombat.com/u/CryptiCrystal)\
**Post date:** [November 30, 2020, 9:55pm UTC](https://discourse.codecombat.com/t/kelvintaph-crusader-help-codecombat/25660/6 "2020-11-30T21:55:35Z")

</div>

Why doesn’t this work?

```python
while True:
    command()
    move()
def command():
    friends = hero.findFriends()
    witch = hero.findNearest(hero.findByType("witch"))
    for friend in friends:
        enemy = friend.findNearestEnemy()
        if witch:
            hero.command(friend, "attack", witch)
        else:
            hero.command(friend, "attack", enemy)
def move():
    hero.moveXY(69, 14)
    hero.wait(2)
    hero.moveXY(15, 14)

```

---

<div class="post-metadata">

**Author:** ![jka2706](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/jka2706/32/13636_2.png) [@jka2706](https://discourse.codecombat.com/u/jka2706)\
**Post date:** [December 1, 2020, 12:52pm UTC](https://discourse.codecombat.com/t/kelvintaph-crusader-help-codecombat/25660/7 "2020-12-01T12:52:44Z")

</div>

Hi CryptiCrystal,

I think part of the problem is that you’re using hero.moveXY. While the hero is moving, no other code runs, so your allies tend to just stand there and be killed. Try hero.move instead.

Do you have the Emperor’s Gloves? They’re useful for this level. I found I also needed to be clever about which friend to command to attack which enemy.

Hope that helps.

Jenny

---

<div class="post-metadata">

**Author:** ![CryptiCrystal](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/crypticrystal/32/16228_2.png) [@CryptiCrystal](https://discourse.codecombat.com/u/CryptiCrystal)\
**Post date:** [December 1, 2020, 3:32pm UTC](https://discourse.codecombat.com/t/kelvintaph-crusader-help-codecombat/25660/8 "2020-12-01T15:32:27Z")

</div>

I do have emperor’s gloves, the chain-lightning ones, right?

---

<div class="post-metadata">

**Author:** ![CryptiCrystal](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/crypticrystal/32/16228_2.png) [@CryptiCrystal](https://discourse.codecombat.com/u/CryptiCrystal)\
**Post date:** [December 1, 2020, 3:35pm UTC](https://discourse.codecombat.com/t/kelvintaph-crusader-help-codecombat/25660/9 "2020-12-01T15:35:41Z")

</div>

```python
while True:
    command()
    move()
def command():
    friends = hero.findFriends()
    witch = hero.findNearest(hero.findByType("witch"))
    for friend in friends:
        enemy = friend.findNearestEnemy()
        if witch:
            hero.command(friend, "attack", witch)
        else:
            hero.command(friend, "attack", enemy)
def move():
    hero.move({'x': 69, 'y': 14})
    hero.wait(2)
    hero.move({'x': 15, 'y': 14})

```

Well, this doesn’t work, because then I move forward a little, then again forward a little, then I die.

---

<div class="post-metadata">

**Author:** ![jka2706](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/jka2706/32/13636_2.png) [@jka2706](https://discourse.codecombat.com/u/jka2706)\
**Post date:** [December 1, 2020, 3:42pm UTC](https://discourse.codecombat.com/t/kelvintaph-crusader-help-codecombat/25660/10 "2020-12-01T15:42:57Z")

</div>

Chain lightening works through the walls, so you can help your friends…

It took me 133 lines of code to solve this with the bonus. Admittedly my code isn’t the nicest - I’m sure there’s plenty of people who have done it with fewer lines (and theres a function in there that I didn’t use)! But keep playing with different ways to get different characters doing different things.

Jenny

---

<div class="post-metadata">

**Author:** ![CryptiCrystal](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/crypticrystal/32/16228_2.png) [@CryptiCrystal](https://discourse.codecombat.com/u/CryptiCrystal)\
**Post date:** [December 1, 2020, 3:43pm UTC](https://discourse.codecombat.com/t/kelvintaph-crusader-help-codecombat/25660/11 "2020-12-01T15:43:58Z")

</div>

Yes I did notice that chain lightning goes through walls. I didn’t test that until now. I think that will help 🙂

---

<div class="post-metadata">

**Author:** ![CryptiCrystal](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/crypticrystal/32/16228_2.png) [@CryptiCrystal](https://discourse.codecombat.com/u/CryptiCrystal)\
**Post date:** [December 1, 2020, 4:03pm UTC](https://discourse.codecombat.com/t/kelvintaph-crusader-help-codecombat/25660/12 "2020-12-01T16:03:26Z")

</div>

I’m So CLOSE. I can’t figure out how to make the hero go to the X when the catapults are dead. I’ll show my code.

```python
while True:
    command()
    move()
def command():
    friends = hero.findFriends()
    witch = hero.findNearest(hero.findByType("witch"))
    for friend in friends:
        enemy = friend.findNearestEnemy()
        if witch:
            if friend.type == 'paladin' and not witch:
                hero.command(friend, "shield")
            else:
                hero.command(friend, "attack", witch)
        else:
            if enemy:
                hero.command(friend, "attack", enemy)
            else:
                hero.command(friend, "move", {'x': 78, 'y': 40})
def move():
    enemy = hero.findNearestEnemy()
    catapults = hero.findByType("catapult")
    if hero.isReady("chain-lightning") and enemy:
        hero.cast("chain-lightning", enemy)
    else:
        hero.move({'x': 68, 'y': 14})
        if hero.pos.x == 68 and hero.pos.y == 14:
            for catapult in catapults:
                if catapult:
                    hero.wait(1)
                    hero.moveXY(11, 14)
                elif catapult.health <= 0:
                    hero.moveXY(78, 14)

```

---

<div class="post-metadata">

**Author:** ![Eric\_Tang](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/eric_tang/32/15310_2.png) [@Eric\_Tang](https://discourse.codecombat.com/u/Eric_Tang)\
**Post date:** [December 1, 2020, 4:25pm UTC](https://discourse.codecombat.com/t/kelvintaph-crusader-help-codecombat/25660/13 "2020-12-01T16:25:02Z")

</div>

I havent done this level yet but you could do

```python
if enemy,health < 0:
#move to the x

```
