# [SOLVED] Level: while ogres were sleeping

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

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

3 Likes

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.

2 Likes

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.

3 Likes

Ок, 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 ?

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

1 Like

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

2 Likes

И да, вы правы, не `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)

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?

3 Likes

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, which shows all essentials of this board! Thanks!

2 Likes

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

2 Likes