Python Python Collections (2016, retired 2019) Dungeon Game Hit points

Igor Ozherelyev
Igor Ozherelyev
2,052 Points

It works well in terminal but workspace says it's wrong

It works well in terminal but workspace says it's wrong
# move((1, 1, 10), (-1, 0)) => (0, 1, 10)
# move((0, 1, 10), (-1, 0)) => (0, 1, 5)
# move((0, 9, 5), (0, 1)) => (0, 9, 0)

def move(player, direction):
    x, y, hp = player
    x1, y1 = direction
    if x + x1 < 0 or x + x1 > 9 or y + y1 < 0 or y + y1 > 9:
        hp -= 5
    return x, y, hp

2 Answers

Eric McKibbin
Eric McKibbin
11,482 Points

Hi Igor,

As well as updating the HP, and not moving the player, when a player would hit a wall, you also need to update the player's position (the returned x, y values) when the player has a valid move (that does not hit a wall).

Good luck!


Steven Parker
Steven Parker
200,781 Points

How did you test it? I tried passing the arguments shown in the examples and none of them produce the output the example shows to expect.

In fact, in all of the tests, the outputs are exactly the same as the inputs. That might serve as a hint. :wink:

Also, just in general you should always bear in mind that the workspaces don't know anything about the challenge objectives. If you misinterpret the objectives, you can write code that will seem to perform correctly in the workspace, but will still not pass the challenge. The same can happen if your testing is less stringent than the challenges. You can count on the challenge to always use more stringent tests internally than those shown in the examples.