Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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 M
Eric M
11,516 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
218,691 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.