Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

[SOLVED] Please help me with black diamond

hi. i’ having trouble with this level, can anyone help me?
here’s my code:

while True:
    gem = hero.findNearest(hero.findItems())
    if gem:
        clear = hero.isPathClear(hero.pos, gem.pos)
        # The isPathClear method tells you if there’s an obstacle in the way.
        # If it’s clear, move() to gem.pos.
        if hero.isPathClear(gem.pos, {"x":40, "y":35}) == False:
            hero.moveXY(40, 35)
        if clear:

Instead of this put an else.
Do you need any more assistance at this level?

Or to keep it simpler, keep this statement, and then underneath put an else (ie for all other possibilities).

i need to grab all the gems, so is it possible to store the gems pos in a variable and keep it after i pick it up?

My code let me collect all the gems with a ‘if clear move to gem; else move to the middle’ structure. If you’ve tried it and it still isn’t working, can you post your code again?

doesn’t the hero go directly into the bear traps if he goes to the middle after having picked a gem that was hidden behind bear traps?

well it worked :joy:
i beat the level :partying_face:

Congratulations! Sorry I could not help more, but I was busy.

it’s fine :grin: :grin:

1 Like