# \[SOLVED\] The One Wizard (python)

**URL:** <https://discourse.codecombat.com/t/solved-the-one-wizard-python/33024>\
**Category:** Level Help\
**Created:** [May 19, 2022, 1:58am UTC](https://discourse.codecombat.com/t/solved-the-one-wizard-python/33024 "2022-05-19T01:58:48Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Albert\_Wu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/albert_wu/32/22942_2.png) [@Albert\_Wu](https://discourse.codecombat.com/u/Albert_Wu)\
**Post date:** [May 19, 2022, 1:58am UTC](https://discourse.codecombat.com/t/solved-the-one-wizard-python/33024/1 "2022-05-19T01:58:48Z")

</div>

Hi everyone in this level I’m having some trouble(I want to get 44 kills) , anyone can help me?  
This is my code.

```python
def enemy():
    enemy = hero.findNearestEnemy()
    if enemy:
        distance = hero.distanceTo(enemy)
        if enemy.type == "orge":
            hero.moveXY(5, 29)
        if distance < 25 and enemy.type == "munchkin" or "scout":
            if hero.canCast("lightning-bolt"):
                hero.cast("lightning-bolt", enemy)
            elif hero.canCast("chain-lightning") and distance < 15:
                hero.cast("chain-lightning", enemy)
            elif hero.canCast("roge"):
                hero.cast("roge")
            else:
                hero.attack(enemy)
    elif hero.canCast("regen",hero):
        hero.cast("regen", hero)
    else:
        hero.moveXY(5, 33)

while True:
    enemy()

```

I am a student so I can’t reply to the message right away, and my English is not good so if my word have some grammatical error do not blame me.

Thanks.

---

<div class="post-metadata">

**Author:** ![phoenixRider2022](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/phoenixrider2022/32/29463_2.png) [@phoenixRider2022](https://discourse.codecombat.com/u/phoenixRider2022)\
**Post date:** [May 19, 2022, 2:43am UTC](https://discourse.codecombat.com/t/solved-the-one-wizard-python/33024/2 "2022-05-19T02:43:47Z")

</div>

> [@Albert\_Wu](#):
>
> ```python
> if enemy.type == "orge":
> hero.moveXY(5, 29)
> 
> ```

so the enemy.type == “ogre” should be enemy.team == “ogres” instead 🙂

---

<div class="post-metadata">

**Author:** ![phoenixRider2022](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/phoenixrider2022/32/29463_2.png) [@phoenixRider2022](https://discourse.codecombat.com/u/phoenixRider2022)\
**Post date:** [May 19, 2022, 2:49am UTC](https://discourse.codecombat.com/t/solved-the-one-wizard-python/33024/3 "2022-05-19T02:49:11Z")

</div>

Also how much time did you make it?

---

<div class="post-metadata">

**Author:** ![Albert\_Wu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/albert_wu/32/22942_2.png) [@Albert\_Wu](https://discourse.codecombat.com/u/Albert_Wu)\
**Post date:** [May 19, 2022, 2:51am UTC](https://discourse.codecombat.com/t/solved-the-one-wizard-python/33024/4 "2022-05-19T02:51:35Z")

</div>

only 37.2s.  
and this is my new code

```python
def enemy():
    enemy = hero.findNearestEnemy()
    if enemy:
        distance = hero.distanceTo(enemy)
        if enemy.type == "orge":
            hero.moveXY(5, 29)
        if distance < 25 and enemy.team == "munchkin" or "scout":
            if hero.canCast("lightning-bolt"):
                hero.cast("lightning-bolt", enemy)
            elif hero.canCast("chain-lightning") and distance < 15:
                hero.cast("chain-lightning", enemy)
            elif hero.canCast("roge"):
                hero.cast("roge",enemy)
            elif hero.canCast("regen",hero):
                hero.cast("regen", hero)
            else:
                hero.attack(enemy)
        elif hero.canCast("roge"):
            hero.cast("roge",enemy)
        elif hero.canCast("regen",hero):
            hero.cast("regen", hero)
        else:
            hero.attack(enemy)
    elif hero.canCast("regen",hero):
        hero.cast("regen", hero)
    else:
        hero.moveXY(5, 33)

while True:
    enemy()

```

thank you

---

<div class="post-metadata">

**Author:** ![phoenixRider2022](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/phoenixrider2022/32/29463_2.png) [@phoenixRider2022](https://discourse.codecombat.com/u/phoenixRider2022)\
**Post date:** [May 19, 2022, 2:56am UTC](https://discourse.codecombat.com/t/solved-the-one-wizard-python/33024/5 "2022-05-19T02:56:43Z")

</div>

> [@Albert\_Wu](#):
>
> ```python
> elif hero.canCast("roge"):
> hero.cast("roge",enemy)
> 
> ```

is there a roge spell?

---

<div class="post-metadata">

**Author:** ![Albert\_Wu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/albert_wu/32/22942_2.png) [@Albert\_Wu](https://discourse.codecombat.com/u/Albert_Wu)\
**Post date:** [May 19, 2022, 3:01am UTC](https://discourse.codecombat.com/t/solved-the-one-wizard-python/33024/6 "2022-05-19T03:01:48Z")

</div>

Ｎo, but don’t know why had before

---

<div class="post-metadata">

**Author:** ![Watamelon](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/watamelon/32/43741_2.png) [@Watamelon](https://discourse.codecombat.com/u/Watamelon)\
**Post date:** [May 19, 2022, 3:05am UTC](https://discourse.codecombat.com/t/solved-the-one-wizard-python/33024/7 "2022-05-19T03:05:11Z")

</div>

I can give you a tip, don’t use while True. The seed is always the same, so therefore you can hard-code functions.

For example, this is a function for attacking a munchkin

```python
def attackMunchkin():
    enemy = hero.findNearestEnemy()
    if enemy and enemy.type == "munchkin":
        hero.attack(enemy)
        hero.attack(enemy) # You need 2 hits

```

This is for attacking scout:

```python
def attackScout():
    enemy = hero.findNearestEnemy()
    if enemy and enemy.type == "scout":
        if hero.canCast("root"):
            hero.cast("root", enemy)
        else:
            hero.attack(enemy)

```

---

<div class="post-metadata">

**Author:** ![Watamelon](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/watamelon/32/43741_2.png) [@Watamelon](https://discourse.codecombat.com/u/Watamelon)\
**Post date:** [May 19, 2022, 3:06am UTC](https://discourse.codecombat.com/t/solved-the-one-wizard-python/33024/8 "2022-05-19T03:06:51Z")

</div>

and if you want to wait in place, do this:

```python
def waitFor(time):
    for i in range(time):
        hero.say("wait") #--> talking takes one second.

waitFor(4) #--> wait 4 seconds

```

---

<div class="post-metadata">

**Author:** ![Albert\_Wu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/albert_wu/32/22942_2.png) [@Albert\_Wu](https://discourse.codecombat.com/u/Albert_Wu)\
**Post date:** [May 19, 2022, 3:08am UTC](https://discourse.codecombat.com/t/solved-the-one-wizard-python/33024/9 "2022-05-19T03:08:05Z")

</div>

Thank you but now I’m going to class so after 45 minutes i will come bake

---

<div class="post-metadata">

**Author:** ![Watamelon](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/watamelon/32/43741_2.png) [@Watamelon](https://discourse.codecombat.com/u/Watamelon)\
**Post date:** [May 19, 2022, 3:08am UTC](https://discourse.codecombat.com/t/solved-the-one-wizard-python/33024/10 "2022-05-19T03:08:57Z")

</div>

Okay‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎

---

<div class="post-metadata">

**Author:** ![Albert\_Wu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/albert_wu/32/22942_2.png) [@Albert\_Wu](https://discourse.codecombat.com/u/Albert_Wu)\
**Post date:** [May 19, 2022, 3:47am UTC](https://discourse.codecombat.com/t/solved-the-one-wizard-python/33024/11 "2022-05-19T03:47:42Z")

</div>

I’m come back.  
how do i know how many enemies are there.  
[CodeCombat - Coding games to learn Python and JavaScript](https://codecombat.com/play/level/the-one-wizard)?

---

<div class="post-metadata">

**Author:** ![Watamelon](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/watamelon/32/43741_2.png) [@Watamelon](https://discourse.codecombat.com/u/Watamelon)\
**Post date:** [May 19, 2022, 6:25am UTC](https://discourse.codecombat.com/t/solved-the-one-wizard-python/33024/12 "2022-05-19T06:25:55Z")

</div>

```python
enemies = hero.findEnemies() # this returns an array of all enemies

print(len(enemies)) # len(enemies) is the length of enemies

```

---

<div class="post-metadata">

**Author:** ![Watamelon](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/watamelon/32/43741_2.png) [@Watamelon](https://discourse.codecombat.com/u/Watamelon)\
**Post date:** [May 19, 2022, 6:26am UTC](https://discourse.codecombat.com/t/solved-the-one-wizard-python/33024/13 "2022-05-19T06:26:30Z")

</div>

Btw, this level don’t support the findEnemies() function, so you can’t know how much enemies are there.

---

<div class="post-metadata">

**Author:** ![Albert\_Wu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/albert_wu/32/22942_2.png) [@Albert\_Wu](https://discourse.codecombat.com/u/Albert_Wu)\
**Post date:** [May 19, 2022, 6:34am UTC](https://discourse.codecombat.com/t/solved-the-one-wizard-python/33024/14 "2022-05-19T06:34:23Z")

</div>

```python
def enemy():
    enemy = hero.findNearestEnemy()
    if enemy:
        distance = hero.distanceTo(enemy)
        if enemy.type == "catapult":
            hero.moveXY(5, 29)
        if distance < 25 and enemy.team == "munchkin" or "scout":
            if hero.canCast("lightning-bolt") and enemy.health > 70:
                hero.cast("lightning-bolt", enemy)
            elif hero.canCast("chain-lightning"):
                hero.cast("chain-lightning", enemy)
            elif hero.canCast("roge"):
                hero.cast("roge",enemy)
            elif hero.canCast("root"):
                hero.cast("root",enemy)
                hero.attack(enemy)
            else:
                hero.attack(enemy)
        else:
            hero.attack(enemy)
    elif hero.canCast("regen",hero) and hero.health < 70:
        hero.cast("regen", hero)
    else:
        hero.moveXY(5, 33)

while True:
    enemy()

```

---

<div class="post-metadata">

**Author:** ![Watamelon](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/watamelon/32/43741_2.png) [@Watamelon](https://discourse.codecombat.com/u/Watamelon)\
**Post date:** [May 19, 2022, 6:47am UTC](https://discourse.codecombat.com/t/solved-the-one-wizard-python/33024/15 "2022-05-19T06:47:09Z")

</div>

I don’t suggest you do while True, I rather prefer hard-coding codes cause the seed is same.

---

<div class="post-metadata">

**Author:** ![Albert\_Wu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/albert_wu/32/22942_2.png) [@Albert\_Wu](https://discourse.codecombat.com/u/Albert_Wu)\
**Post date:** [May 19, 2022, 6:53am UTC](https://discourse.codecombat.com/t/solved-the-one-wizard-python/33024/16 "2022-05-19T06:53:31Z")

</div>

but without repeating he could not execute

---

<div class="post-metadata">

**Author:** ![Albert\_Wu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/albert_wu/32/22942_2.png) [@Albert\_Wu](https://discourse.codecombat.com/u/Albert_Wu)\
**Post date:** [May 19, 2022, 7:17am UTC](https://discourse.codecombat.com/t/solved-the-one-wizard-python/33024/17 "2022-05-19T07:17:44Z")

</div>

![截圖 2022-05-19 下午3.16.58](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/2/1/217f3a5635c4b734356e293a03c702eea1b9fc8f.jpeg)  
i got it.  
Thank you.

---

<div class="post-metadata">

**Author:** ![Watamelon](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/watamelon/32/43741_2.png) [@Watamelon](https://discourse.codecombat.com/u/Watamelon)\
**Post date:** [May 19, 2022, 10:47am UTC](https://discourse.codecombat.com/t/solved-the-one-wizard-python/33024/18 "2022-05-19T10:47:31Z")

</div>

Your welcome, glad it helped.

---

<div class="post-metadata">

**Author:** ![moonwatcher348](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/moonwatcher348/32/24126_2.png) [@moonwatcher348](https://discourse.codecombat.com/u/moonwatcher348)\
**Post date:** [May 19, 2022, 4:44pm UTC](https://discourse.codecombat.com/t/solved-the-one-wizard-python/33024/19 "2022-05-19T16:44:11Z")

</div>

It does actually support the `findEnemies()` function, I used it.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/a/a9445509d1a758c41b5ddcddc8c8e20a5dedb67f.png) [@system](https://discourse.codecombat.com/u/system)\
**Post date:** [May 20, 2022, 4:45am UTC](https://discourse.codecombat.com/t/solved-the-one-wizard-python/33024/20 "2022-05-20T04:45:06Z")

</div>

Closed on May 20, 2022, 4:45am UTC

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.
