Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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

Daniel Bourke
Daniel Bourke
3,870 Points

I'm having trouble understanding what exactly this question is asking.

Hey guys,

I'm stuck on this challenge mostly because I'm having trouble understanding the code/question.

The example shows a move function that takes in two arguments.

I'm having trouble with the first argument, the x, y, "hp"? How does it manage to go from (0, 1, 10) to (0, 9, 5)?

I understand it loses hp, but I can't conceptualise the transition from 1 to 9, unless it moves through the wall?

If anyone could explain the question in a different way, that would be greatly appreciated!

Thank you.

movement.py
# EXAMPLES:
# 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

    return x, y, hp

1 Answer

Brendan Whiting
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,735 Points

These 3 test cases are independent. The output of the 1st case happens to be in input of the 2nd, but the 3rd case is not related at all. Let’s break down the 3 test cases:

# move((1, 1, 10), (-1, 0)) => (0, 1, 10)

Player’s x position is 1, he’s asking to move -1 in the x direction. That’s allowed so now his x position is 0, and his hit points are the same.

# move((0, 1, 10), (-1, 0)) => (0, 1, 5)

Player’s x position is 0, he’s asking to move -1 in the x direction. That’s not allowed so 5 points are subtracted from his hit points and his x position is still 0.

# move((0, 9, 5), (0, 1)) => (0, 9, 0)

Player’s y position is 9, he’s asking to move 1 in the y direction. That’s not allowed so 5 points are subtracted from his hit points and his y position is still 9.

Daniel Bourke
Daniel Bourke
3,870 Points

Thanks, Brendan!

That was confusing me. I managed to solve it in the end.