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

Abdulkadir Kollere
Abdulkadir Kollere
1,723 Points

couldn't find 'move'

I have done what was asked in the challenge but I get the error "couldn't find 'move'". Any help will be appreciated

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
    if x == 0 & move_made == "Left" | x == 8 & move_made == "Right" | y == 0 & move_made == "Up" | y == 8 & move_made == "Down":
        hp -= 5

    if x == 0:
        move_made.remove('Left')
    if x == 8:
        move_made.remove('Right')
    if y == 0:
        move_made.remove('Up')
    if y == 8:
        move_made.remove('Down')
    return x, y, hp

1 Answer

Hi there,

What is move_made? Where is it defined?

Also, your moves are strings. The direction variable contains a tuple that is an x, y coordinate change of the move; the example given in the question is, a direction tuple that's two parts, the x to move and the y (like (-1, 0) would move to the left but not up or down). We can't assume only a single-unit move can be made at once, though, but all the examples suggest such. The move is a numeric change of coordinate, not a string representation.

You need to start by determining the x & y position of the player - that's given as a parameter in a three-part tuple which has been processed into three variables for you. Then add in the move from the direction tuple. Lastly, if either x or y is less than 0 or more than 9, modify the hp of the player from the three-part tuple. Also, reset the value back to zero or 9, depending which bound the player broke - that way, the player isn't left beyond the wall.

I'm no Python programmer at all so this is an ugly solution, but it works merely by way of illustrating the above explanation. I am sure there is a far more elegant solution which you should try to find!

def move(player, direction):
    x, y, hp = player
    dx, dy = direction  # determine the change of x & y
    x = x + dx    # apply the changes
    y = y + dy
    if x < 0:       # if it went beyond the wall
        x = 0       # reset its position
        hp -= 5    # reduce hp
    if x > 9:      # repeat for each wall
        x = 9
        hp -= 5
    if y < 0:
        y = 0
        hp -= 5    
    if y > 9:
        y = 9
        hp -= 5
    return x, y, hp

Make sense?

Steve.

Abdulkadir Kollere
Abdulkadir Kollere
1,723 Points

Makes sense. That opened up my thoughts. Thanks!

Glad to help! :+1: :smile: