[SOLVED] Hero Dies in Usual Day (Python)


#1

New here. I’m trying to play Usual Day and for some reason, towards the end of the level, a mushroom appears and an enemy appears right in line with the mushroom. The hero goes towards the enemy, getting the mushroom on the way and dies.

Defeat munchkins, collect coins. Everything as usual.

Use AND to check existence and type in one statement.

while True:
enemy = hero.findNearestEnemy()
# With AND, the type is only checked if enemy exists.
if enemy and enemy.type == “munchkin”:
hero.attack(enemy);
# Find the nearest item.
item = hero.findNearestItem()
# Collect item if it exists and its type is “coin”.
if item and item.type == “coin”:
hero.moveXY (item.pos.x, item.pos.y);

I can have the hero move to another spot to avoid the mushroom but that’s eight lines of code and won’t complete the level.


#2
while True:
enemy = hero.findNearestEnemy()
# With AND, the type is only checked if enemy exists.
if enemy and enemy.type == "munchkin":
hero.attack(enemy);
# Find the nearest item.
item = hero.findNearestItem()
# Collect item if it exists and its type is "coin".
if item and item.type == "coin":
hero.moveXY (item.pos.x, item.pos.y);

No that is only 7 lines, so you should be able to complete the level. Also, make sure you format the code by wrapping it with three ticks. The result is easier to read.


#3
while True:
    enemy = hero.findNearestEnemy()
    # With AND, the type is only checked if enemy exists.
    if enemy and enemy.type == "munchkin":
        hero.attack(enemy);
    # Find the nearest item.
    item = hero.findNearestItem()
    # Collect item if it exists and its type is "coin".
    if item and item.type == "coin":
        hero.moveXY (item.pos.x, item.pos.y);

That’s better. It wants you to do it with under eight lines of code and that’s the seven lines. I’ll try with a different hero and see what happens.


#4

Sure, try it with another hero. I tried that exact same code and it worked for me. I counted, only 7 lines, so it should fall into the under 8 category.


#5

Well. it works now. I logged off, logged back in and played it. I guess it’s just the way the objects were being spawned on that first round. It just so happened a poisonous mushroom was in the way of getting to an enemy. Thanks!


#6

I think the mushroom is there on purpose. And there is a trick to avoid it!

In the last line, don’t go exactly to the item, you can pick it up even if you go to

hero.moveXY (item.pos.x-1, item.pos.y-1);

This way the distance to mushroom is long enough to avoid it :slight_smile:


#7

Or submit for a different seed. Also, please do not revive dead threads :slight_smile: