# \[SOLVED\] Level: while ogres were sleeping

**URL:** <https://discourse.codecombat.com/t/solved-level-while-ogres-were-sleeping/24922>\
**Category:** Bugs\
**Created:** [October 23, 2020, 6:55am UTC](https://discourse.codecombat.com/t/solved-level-while-ogres-were-sleeping/24922 "2020-10-23T06:55:52Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![11179](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/11179/32/15754_2.png) [@11179](https://discourse.codecombat.com/u/11179)\
**Post date:** [October 23, 2020, 6:55am UTC](https://discourse.codecombat.com/t/solved-level-while-ogres-were-sleeping/24922/1 "2020-10-23T06:55:52Z")

</div>

This level (while ogres were sleeping) is broken. I foundsolution on youtube but it is doesn’t work for me.  
I can’t defeat munchkin

---

<div class="post-metadata">

**Author:** ![xython](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/xython/32/7269_2.png) [@xython](https://discourse.codecombat.com/u/xython)\
**Post date:** [October 23, 2020, 8:06am UTC](https://discourse.codecombat.com/t/solved-level-while-ogres-were-sleeping/24922/2 "2020-10-23T08:06:52Z")

</div>

The level is OK. Did’t test the video code but delete the youtube link. There are so many copy/paste fans …

 ![sleep](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/f/fcad9ee1bbce906d9210527bc3fc11d377ebdb0d.gif)

---

<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:** [October 23, 2020, 8:37am UTC](https://discourse.codecombat.com/t/solved-level-while-ogres-were-sleeping/24922/3 "2020-10-23T08:37:13Z")

</div>

> [@11179](#):
>
> but it is doesn’t work for me.

That doesn’t necessarily mean it’s broken. My advice is always to write your own, code. I promise you it’s much easier than trying to fix a dodgy solution.

---

<div class="post-metadata">

**Author:** ![Alexbrand](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@Alexbrand](https://discourse.codecombat.com/u/Alexbrand)\
**Post date:** [October 23, 2020, 9:46am UTC](https://discourse.codecombat.com/t/solved-level-while-ogres-were-sleeping/24922/4 "2020-10-23T09:46:14Z")

</div>

Levels are patched from time to time to fix cheat solutions.  
I don’t wanna to seem mean, but if copied from Internet code for level doesn’t work - maybe the question “Why?!” should be addressed to the code author?)  
Guys are right, it’s better to wright code by oneself.

---

<div class="post-metadata">

**Author:** ![11179](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/11179/32/15754_2.png) [@11179](https://discourse.codecombat.com/u/11179)\
**Post date:** [October 23, 2020, 10:15am UTC](https://discourse.codecombat.com/t/solved-level-while-ogres-were-sleeping/24922/5 "2020-10-23T10:15:13Z")

</div>

Ок, then i need a help with this level.

# Враги спят. Отличное время для диверсии.

points = [{“x”: 21, “y”: 8}, {“x”: 33, “y”: 8},  
{“x”: 45, “y”: 8}, {“x”: 57, “y”: 8}, {“x”: 68, “y”: 8},  
{“x”: 68, “y”: 18}, {“x”: 68, “y”: 28},  
{“x”: 68, “y”: 38}, {“x”: 68, “y”: 48},  
{“x”: 68, “y”: 58}, {“x”: 56, “y”: 58},  
{“x”: 44, “y”: 58}, {“x”: 32, “y”: 58},  
{“x”: 20, “y”: 58}, {“x”: 10, “y”: 60}]

pointIndex = 0;

while pointIndex \< len(points):  
point = points[pointIndex];  
hero.moveXY(point[“x”], point[“y”])  
enemy = hero.findNearestEnemy()  
coin = hero.findNearestItem()  
# Атакуй только если enemy.team “огры”  
# И если здоровье противника меньше 10  
if enemy.type == “ogres” and enemy.health \< 10:  
hero.attack(enemy)  
# Взять монету если coin.value меньше 5  
# И если расстояние меньше 7  
if coin.value \< 5 and hero.distanceTo(coin) \< 7:  
hero.moveXY(coin.pos.x, coin.pos.y)  
# Атаковать только если enemy.health(здоровье противника) меньше чем 10  
# И атаковать если враг типа “skeleton”(скелет).  
if enemy and enemy.type == “skeleton” and enemy.health \< 10 and hero.distanceTo(enemy) \> 9:  
hero.attack(enemy)  
pointIndex += 1

Ok, this is my code and this code like code from youtube. I was thinking, i have a problem with munchkin and use this part in the end:  
hero.moveXY(10, 60)  
enemy = hero.findNearestEnemy()  
if enemy and hero.distanceTo(enemy) \< 10:  
hero.attack(enemy)

But it is doesn’t work. Where is a problem ? Can you help me ?

---

<div class="post-metadata">

**Author:** ![Alexbrand](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@Alexbrand](https://discourse.codecombat.com/u/Alexbrand)\
**Post date:** [October 23, 2020, 10:25am UTC](https://discourse.codecombat.com/t/solved-level-while-ogres-were-sleeping/24922/6 "2020-10-23T10:25:59Z")

</div>

Ok, lets take a look… Попробуем тряхнуть стариной)

---

<div class="post-metadata">

**Author:** ![Alexbrand](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@Alexbrand](https://discourse.codecombat.com/u/Alexbrand)\
**Post date:** [October 23, 2020, 11:40am UTC](https://discourse.codecombat.com/t/solved-level-while-ogres-were-sleeping/24922/7 "2020-10-23T11:40:18Z")

</div>

First of all, could you please edit your post to format code properly according to this instructions [https://discourse.codecombat.com/t/essentials-how-to-post-format-your-code-correctly/15521](https://discourse.codecombat.com/t/essentials-how-to-post-format-your-code-correctly/15521)

---

<div class="post-metadata">

**Author:** ![Alexbrand](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@Alexbrand](https://discourse.codecombat.com/u/Alexbrand)\
**Post date:** [October 23, 2020, 12:40pm UTC](https://discourse.codecombat.com/t/solved-level-while-ogres-were-sleeping/24922/8 "2020-10-23T12:40:50Z")

</div>

И да, вы правы, не `and hero.distanceTo(enemy)` **`_>_`** `9:` там нужно)

UPD  
It’s funny and looks like @11179 is right a bit - the level was changed and one of conditions for the third shift was turned from smth like “distance” to “skeleton” and this causes failure)

> [@11179](#):
>
> while pointIndex \< len(points):  
> point = points[pointIndex];  
> hero.moveXY(point[“x”], point[“y”])  
> enemy = hero.findNearestEnemy()  
> coin = hero.findNearestItem()
> 
> # Атакуй только если enemy.team “огры”
> 
> # И если здоровье противника меньше 10
> 
> if enemy.type == “ogres” and enemy.health \< 10:  
> hero.attack(enemy)
> 
> # Взять монету если coin.value меньше 5
> 
> # И если расстояние меньше 7
> 
> if coin.value \< 5 and hero.distanceTo(coin) \< 7:  
> hero.moveXY(coin.pos.x, coin.pos.y)
> 
> # Атаковать только если enemy.health(здоровье противника) меньше чем 10
> 
> # И атаковать если враг типа “skeleton”(скелет).
> 
> if enemy and enemy.type == “skeleton” and enemy.health \< 10 and hero.distanceTo(enemy) \> 9:  
> hero.attack(enemy)  
> pointIndex += 1

In fact there are only two little mistakes in your code.  
Try to look closer at the comment and the line of your code:  
`# Атакуй только если enemy.team “огры”`  
`if enemy.type == “ogres” and enemy.health < 10:`  
team!=type  
And the second one is about distance. Maybe you don’t want to attack skeleton if the distance is **more** then 9?

---

<div class="post-metadata">

**Author:** ![Monsty](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/monsty/32/20923_2.png) [@Monsty](https://discourse.codecombat.com/u/Monsty)\
**Post date:** [October 24, 2020, 5:25pm UTC](https://discourse.codecombat.com/t/solved-level-while-ogres-were-sleeping/24922/9 "2020-10-24T17:25:28Z")

</div>

Hello and welcome to codecombat discourse @11179! This is a cozy forum where you can share ideas, share fan art, get assistance for code, etc! Before you proceed, we hope that you review [this topic](https://discourse.codecombat.com/t/welcome-to-codecombat-discourse-forums/15601), which shows all essentials of this board! Thanks!

---

<div class="post-metadata">

**Author:** ![11179](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/11179/32/15754_2.png) [@11179](https://discourse.codecombat.com/u/11179)\
**Post date:** [October 26, 2020, 3:26am UTC](https://discourse.codecombat.com/t/solved-level-while-ogres-were-sleeping/24922/10 "2020-10-26T03:26:35Z")

</div>

Thank you. I found my mistake. I try use team instead type, but previosly it is doent’s work. Maybe it was another version of my code with another mistake

---

<div class="post-metadata">

**Author:** ![Alexbrand](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@Alexbrand](https://discourse.codecombat.com/u/Alexbrand)\
**Post date:** [October 26, 2020, 9:48am UTC](https://discourse.codecombat.com/t/solved-level-while-ogres-were-sleeping/24922/11 "2020-10-26T09:48:11Z")

</div>


