# CS50 FIFTEEN all moves are illegal?

Hey! My name is Samuel and I'm 14 years old. I am doing fifteen.c in problem set four. My program compiles and runs perfectly and my initiate and draw functions seem to work correctly as well. Though, when I try to move a number, I find that every move is illegal. Could someone please help me with my "move" function?

``````bool move(int tile)
{
int blank_space = 0, temp;

if (tile == 0)
{
return false;
}
for (int i = 0; i < d; i++)
{
for (int j = 0; j < d; j++)
{
if (board[i][j] == tile)
{
if (j > 0)
{
if (board[i-0][j-1] == blank_space)
{
temp = board[i][j];
blank_space = board[i-0][j-1];
board[i][j] = temp;
return true;
}
}
if (j > d-1)
{
if (board[i-1][j-0] == blank_space)
{
temp = board[i][j];
blank_space = board[i-1][j-0];
board[i][j] = temp;
return true;
}
}
if (i < 0)
{
if (board[i+0][j+1] == blank_space)
{
temp = board[i][j];
blank_space = board[i+0][j+1];
board[i][j] = temp;
return true;
}
}
if (i < d-1)
{
if (board[i+1][j+0] == blank_space)
{
temp = board[i][j];
blank_space = board[i+1][j+0];
board[i][j] = temp;
return true;
}
}
}
}
}
return false;
}
``````

Thank you! :D,

From,

Samuel

Two problems jump out that at least contribute to the problem. When will this `if (j > d-1)` evaluate to true? When will this `if (i < 0)` evaluate to true?