## 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!

### 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.  # Can someone suggest a correction to the Dungeon get_moves() function?

Hi all, I read all the previous questions/answers regarding the error in the code regarding the get_moves() function. But I can't seem to find a solution to it - can someone suggest one? Thanks!

Here is a reminder of the code:

```def get_moves(player):
x, y = player
moves = ['LEFT', 'RIGHT', 'UP', 'DOWN']

if x == 0:
moves.remove('UP')
if y == 0:
moves.remove('DOWN')
if x == GAME_DIMENSIONS-1:
moves.remove('RIGHT')
if y == GAME_DIMENSIONS-1:
moves.remove('DOWN')
return moves
```

The result in the console shows:

```>>> from dd_game import get_moves
>>> GAME_DIMENSIONS = (2,2)
>>> get_moves((2,2))
['LEFT','RIGHT','UP','DOWN']
>>> get_moves((1,1))
['LEFT','RIGHT','UP','DOWN']
```

First question: why do we need '-1' in x == GAME_DIMENSIONS - 1? If I a in cell (2,2), I should just have x == GAME_DIMENSIONS.

Second question: if I am in (1,1), I should fill the conditions x == GAME_DIMENSIONS-1 (2-1=1) and y == GAME_DIMENSIONS-1 (2-1 =1), but why do I still get 'RIGHT' and 'DOWN' in my list of possible moves?

Thanks! MOD First question: why do we need '-1' in x == GAME_DIMENSIONS - 1?

The GAME_DIMENSIONS are given in natural numbers (1, 2, 3, ...). That is, a 3 means there are three positions. Since the code in python is using the 0-based indexing, the three positions would be numbered 0, 1, 2. The "- 1" is used to correctly compare the maximum dimension with the maximum python index. If I a in cell (2,2), I should just have x == GAME_DIMENSIONS.

Given `GAME_DIMENSIONS = (2,2)`, the position "(2, 2)" would be outside of the game grid where the maximum position would be (1, 1) out of the list `[(0, 0), (0, 1), (1, 0), (1, 1)]` Second question: if I am in (1,1), I should fill the conditions x == GAME_DIMENSIONS-1 (2-1=1) and y == GAME_DIMENSIONS-1 (2-1 =1), but why do I still get 'RIGHT' and 'DOWN' in my list of possible moves?

Look again at which direction is being removed. Each direction should only have one way to removed it. "Down" appears to have two ways to delete it. Also, be sure that the x and y components are only affecting on direction. Either x does "UP" and "DOWN" and y does "LEFT" and "RIGHT" or vise versa. You have x limiting "UP" and y limiting "DOWN".

Post back if you need more help. Good luck!! Hi Chris, thanks a lot for this! Points 1 and 2 are clear.

Regarding Point 3, you're right, I have altered my code to look like this now, so RIGHT, LEFT, UP and DOWN are only removed once.

```def get_moves(player):
x, y = player
moves = ['LEFT', 'RIGHT', 'UP', 'DOWN']

if y == 0:
moves.remove('UP')
if x == 0:
moves.remove('LEFT')
if x == GAME_DIMENSIONS-1:
moves.remove('RIGHT')
if y == GAME_DIMENSIONS-1:
moves.remove('DOWN')
return moves
```

However I still get the exact same result in the console:

```>>> from dd_game import get_moves
>>> GAME_DIMENSIONS = (2,2)
>>> get_moves((1,1))
['LEFT', 'RIGHT', 'UP', 'DOWN']
``` ```GAME_DIMENSIONS = (2,2)