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 (Retired) Dungeon Game Building the Game: Part 1

Sergei Miroshnikov
Sergei Miroshnikov
3,313 Points

Why we are skipping the case when player is located at corner e.g (0,0), in that case we have only 2 directions to move

CELLS = [(0,0),(0,1),(0,2),(1,0),(1,1),(1,2)]

so if player is at(0,0) he can move only 'DOWN' and 'RIGHT' . Why Kenneth omitted that in his lecture ?

2 Answers

Nathan Tallack
Nathan Tallack
22,159 Points

The get_moves function is using separate if statements for each direction. Consider the function code below:

def get_moves(player):
    moves = ['(L)eft', '(R)ight', '(U)p', '(D)own']

    if player[1] == 0:
        moves.remove('(L)eft')
    if player[1] == 2:
        moves.remove('(R)ight')
    if player[0] == 0:
        moves.remove('(U)p')
    if player[0] == 2:
        moves.remove('(D)own')

    return moves

If the player is at 0,0 then the first and the third condition would be true removing left and up from the moves variable.

So this would satisfy the condition that you are mentioning in your question.

Does that make sense?